国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術(shù)文章
文章詳情頁

SpringBoot Service和Dao的編寫詳解

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

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

效果圖

SpringBoot Service和Dao的編寫詳解

配置環(huán)境

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

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

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對應(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

# 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);}

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

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 成人久久久久久 | 亚洲aⅴ | 欧美一级特毛片 | 精品国产精品a | 久久精品国产亚洲7777 | 久久久久欧美情爱精品 | 日本三级香港三级妇三 | 日韩视频在线观看中字 | 欧美综合在线视频 | 国产成人在线看 | 国内精品久久久久久野外 | 国产精品自拍在线观看 | 亚洲国产精久久久久久久 | 台湾黄三级高清在线观看播放 | 她也啪在线视频精品网站 | 日韩免费专区 | 神马三级我不卡 | 国产精品理论 | 国产一级强片在线观看 | 国产精品无码久久久久 | 久久精品国产免费看久久精品 | 久久91精品国产91久久小草 | 亚洲欧洲视频在线 | 免费特黄级夫费生活片 | 日韩一区二区三区在线播放 | 国产亚洲精品一品区99热 | 久草视频在线播放 | 国产日韩欧美精品 | 中文字幕一区中文亚洲 | 国产精品合集久久久久青苹果 | 美女黄色在线观看 | 国产八区 | 在线成人97观看 | 99久久精品无码一区二区毛片 | 免费视频久久看 | 欧美日韩永久久一区二区三区 | 538在线视频二三区视视频 | 久久99毛片免费观看不卡 | 美女被免费网站视频软件 | 精品久久久久久久久中文字幕 | 欧美日韩亚洲v在线观看 |