av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

SpringBoot Service和Dao的編寫詳解

瀏覽:13日期:2023-04-07 09:58:51

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

效果圖

SpringBoot Service和Dao的編寫詳解

配置環境

創建數據庫

數據庫中文編碼

SpringBoot Service和Dao的編寫詳解

建表

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;

SpringBoot Service和Dao的編寫詳解

pom依賴和配置

mybatis 和 mysql

<!-- connect--><!-- 不同版本mybatis對應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

# mysqlspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/rxguo_test?serverTimezone=UTC&characterEncoding=utf8&useSSL=falsespring.datasource.username=rootspring.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;@RestControllerpublic 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;@Servicepublic 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@Repositorypublic interface StudentMapper { @Select('select * from student where id = #{id}') Student getStudentById(Integer id);}

到此這篇關于SpringBoot Service和Dao的編寫詳解的文章就介紹到這了,更多相關SpringBoot Service和Dao編寫內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 精品区一区二区 | 亚洲精品久久久久久一区二区 | 国产一区二区三区高清 | 在线中文字幕第一页 | 99re6在线视频精品免费 | 国产亚洲一区二区精品 | 免费成人av网站 | 91极品欧美视频 | 午夜影视免费片在线观看 | 日日爱夜夜操 | 色射综合 | 丁香六月激情 | 一区二区精品视频 | 美女爽到呻吟久久久久 | 欧美精品一区二区三区在线 | 三级黄色片在线观看 | 亚洲一区二区av | 精品国产乱码久久久久久图片 | 亚洲欧美在线视频 | 国产高清精品在线 | 99热这里有精品 | 久久中文字幕视频 | 国产jizz女人多喷水99 | 中国毛片免费 | 欧美在线成人影院 | 国产精品永久久久久久久www | www久久久 | 国产精品欧美一区二区 | 四虎最新| 欧美天天视频 | 一区二区三区四区五区在线视频 | 一级免费毛片 | 国产精品女人久久久 | 91视频国产区 | 国产综合av | 欧美在线网站 | 国产伦一区二区三区四区 | 不卡av电影在线播放 | 麻豆天堂 | 秋霞电影一区二区 | 日韩成人精品一区二区三区 |