最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

SpringBoot Service和Dao的編寫詳解

 更新時(shí)間:2020年11月23日 09:14:15   作者:瑞 新  
這篇文章主要介紹了SpringBoot Service和Dao的編寫詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

本文主要介紹了SpringBoot Service和Dao的編寫詳解,分享給大家,具體如下:

效果圖

在這里插入圖片描述

配置環(huán)境

創(chuàng)建數(shù)據(jù)庫(kù)

數(shù)據(jù)庫(kù)中文編碼

在這里插入圖片描述

建表

create table `student` (
	`id` int(11) Not NULL AUTO_INCREMENT COMMENT '主鍵自增id',
	`name` varchar(250) NOT NULL DEFAULT ' ' COMMENT '姓名',
	PRIMARY KEY(`id`)
)ENGINE=INNODB DEFAULT CHARSET=utf8;

在這里插入圖片描述

pom依賴和配置

mybatis 和 mysql

<!--    connect-->
<!--    不同版本mybatis對(duì)應(yīng)boot版本不同-->
    <dependency>
      <groupId>org.mybatis.spring.boot</groupId>
      <artifactId>mybatis-spring-boot-starter</artifactId>
      <version>2.1.1</version>
    </dependency>
<!--    mysql版本可以不指定-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>

application.properties

# mysql
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/rxguo_test?serverTimezone=UTC&characterEncoding=utf8&useSSL=false
spring.datasource.username=root
spring.datasource.password=

java bean

package com.bennyrhys.com.shop.bean;

public class Student {
  Integer id;
  String name;

  public Integer getId() {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  @Override
  public String toString() {
    return "Student{" +
        "id=" + id +
        ", name='" + name + '\'' +
        '}';
  }
}

Controller

package com.bennyrhys.com.shop;

import com.bennyrhys.com.shop.bean.Student;
import com.bennyrhys.com.shop.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StudentController {
  @Autowired
  StudentService studentService;

  @GetMapping("/student")
  public String getStudentById(@RequestParam Integer id) {
    Student student = studentService.getStudentById(id);
    return student.toString();
  }
}

Service

package com.bennyrhys.com.shop.service;

import com.bennyrhys.com.shop.bean.Student;
import com.bennyrhys.com.shop.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StudentService {

  @Autowired
  StudentMapper studentMapper;

  public Student getStudentById(Integer id) {
    return studentMapper.getStudentById(id);
  }
}

Mapper接口

package com.bennyrhys.com.shop.mapper;

import com.bennyrhys.com.shop.bean.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;


@Mapper
@Repository
public interface StudentMapper {
  @Select("select * from student where id = #{id}")
  Student getStudentById(Integer id);
}

到此這篇關(guān)于SpringBoot Service和Dao的編寫詳解的文章就介紹到這了,更多相關(guān)SpringBoot Service和Dao編寫內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • java實(shí)現(xiàn)客房管理系統(tǒng)

    java實(shí)現(xiàn)客房管理系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)客房管理系統(tǒng),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-02-02
  • java并發(fā)之synchronized

    java并發(fā)之synchronized

    這篇文章主要介紹了java并發(fā)關(guān)鍵字synchronized,包括內(nèi)容synchronized的使用、synchronized背后的Monitor、synchronized保證可見(jiàn)性和防重排序、使用synchronized注意嵌套鎖定,具體內(nèi)容請(qǐng)看下面文章吧
    2021-10-10
  • spring Boot與Mybatis整合優(yōu)化詳解

    spring Boot與Mybatis整合優(yōu)化詳解

    關(guān)于spring-boot與mybatis整合優(yōu)化方面的介紹,就是Mybatis-Spring-boot-starter的介紹,具體內(nèi)容詳情大家參考下本文
    2017-07-07
  • 優(yōu)化Java內(nèi)存管理來(lái)防止“GC”錯(cuò)誤的方法詳解

    優(yōu)化Java內(nèi)存管理來(lái)防止“GC”錯(cuò)誤的方法詳解

    垃圾回收(GC)是 Java 中的一個(gè)重要機(jī)制,它可以管理內(nèi)存并回收不再使用的對(duì)象所占用的資源,在本文中,我們將探討一些技巧,幫助您避免這一錯(cuò)誤,確保您的 Java 應(yīng)用程序順利運(yùn)行,需要的朋友可以參考下
    2023-11-11
  • SpringBoot多數(shù)據(jù)源配置方式以及報(bào)錯(cuò)問(wèn)題的解決

    SpringBoot多數(shù)據(jù)源配置方式以及報(bào)錯(cuò)問(wèn)題的解決

    這篇文章主要介紹了SpringBoot多數(shù)據(jù)源配置方式以及報(bào)錯(cuò)問(wèn)題的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Spring Security實(shí)現(xiàn)微信公眾號(hào)網(wǎng)頁(yè)授權(quán)功能

    Spring Security實(shí)現(xiàn)微信公眾號(hào)網(wǎng)頁(yè)授權(quán)功能

    這篇文章主要介紹了Spring Security中實(shí)現(xiàn)微信網(wǎng)頁(yè)授權(quán),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-08-08
  • SpringBoot調(diào)用第三方WebService接口的操作技巧(.wsdl與.asmx類型)

    SpringBoot調(diào)用第三方WebService接口的操作技巧(.wsdl與.asmx類型)

    這篇文章主要介紹了SpringBoot調(diào)第三方WebService接口的操作代碼(.wsdl與.asmx類型 ),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-08-08
  • springboot @RequiredArgsConstructor的概念與使用方式

    springboot @RequiredArgsConstructor的概念與使用方式

    這篇文章主要介紹了springboot @RequiredArgsConstructor的概念與使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-09-09
  • Java使用Arrays.asList報(bào)UnsupportedOperationException的解決

    Java使用Arrays.asList報(bào)UnsupportedOperationException的解決

    這篇文章主要介紹了Java使用Arrays.asList報(bào)UnsupportedOperationException的解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • Mybatis-plus的service通用接口解讀

    Mybatis-plus的service通用接口解讀

    這篇文章主要介紹了Mybatis-plus的service通用接口解讀,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07

最新評(píng)論

法库县| 武穴市| 秦安县| 常德市| 东港市| 台北市| 阿拉善右旗| 哈巴河县| 佛教| 右玉县| 新宾| 新宾| 卢湾区| 西盟| 白水县| 嘉荫县| 陇川县| 衡东县| 光泽县| 旅游| 江达县| 黄石市| 原阳县| 准格尔旗| 昆山市| 三亚市| 白城市| 米林县| 阿荣旗| 宜章县| 黄龙县| 长兴县| 万宁市| 清新县| 类乌齐县| 离岛区| 建昌县| 孟津县| 九江县| 陆河县| 郴州市|