Springboot整合Mybatispuls的實(shí)例詳解
Springboot整合MybatisPuls
Maven導(dǎo)入依賴,主要只需導(dǎo)入MyBatisPuls
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jdbc</artifactId> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.0.1</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency>
配置數(shù)據(jù)源
spring.datasource.username=root spring.datasource.password=root spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC server.port=8082
編寫實(shí)體類
@Data @AllArgsConstructor @NoArgsConstructor @TableName("users")//連接的表名 public class Users implements Serializable { @TableId("id")標(biāo)記該變量為主鍵 private Integer id; private String Account; @TableField("passwraod" )//如果實(shí)體類變量和數(shù)據(jù)庫(kù)不同使用 private String password; private Integer Authority; }
mapper接口編寫
繼承BaseMapper<這里為實(shí)體類>
@org.apache.ibatis.annotations.Mapper//讓Spring容器掃描該類為Mapper @Repository public interface Mapper extends BaseMapper<Users> { }
BaseMapper源碼
實(shí)現(xiàn)接口方法
@RestController public class Control { @Autowired Mapper mapper; @RequestMapping("/hello") public Users Select(){ Users users = mapper.selectById(1); return users; } }
到此這篇關(guān)于Springboot整合Mybatispuls的文章就介紹到這了,更多相關(guān)Springboot整合Mybatispuls內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java int與integer的對(duì)比區(qū)別
這篇文章主要介紹了Java int與integer的對(duì)比區(qū)別的相關(guān)資料,需要的朋友可以參考下2017-01-01關(guān)于Mybatis插入對(duì)象時(shí)空值的處理
這篇文章主要介紹了關(guān)于Mybatis插入對(duì)象時(shí)空值的處理方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06Java中jdk1.8和jdk17相互切換實(shí)戰(zhàn)步驟
之前做Java項(xiàng)目時(shí)一直用的是jdk1.8,現(xiàn)在想下載另一個(gè)jdk版本17,并且在之后的使用中可以進(jìn)行相互切換,下面這篇文章主要給大家介紹了關(guān)于Java中jdk1.8和jdk17相互切換的相關(guān)資料,需要的朋友可以參考下2023-05-05上傳自己的jar包到maven中央倉(cāng)庫(kù)的快速操作方法
網(wǎng)絡(luò)上可以搜索到很多jar包到中央倉(cāng)庫(kù),但是都不是多適合自己的項(xiàng)目,于是自己動(dòng)手寫個(gè),本文檔通過sonatype上傳jar包至maven中央倉(cāng)庫(kù),Sonatype通過JIRA來(lái)管理OSSRH倉(cāng)庫(kù),具體實(shí)例代碼跟隨小編一起看看吧2021-08-08SpringBoot利用攔截器實(shí)現(xiàn)避免重復(fù)請(qǐng)求
Spring MVC中的攔截器(Interceptor)類似于Servlet中的過濾器(Filter),它主要用于攔截用戶請(qǐng)求并作相應(yīng)的處理。本文就將利用攔截器實(shí)現(xiàn)避免重復(fù)請(qǐng)求,感興趣的小伙伴可以了解一下2022-11-11Java ArrayList擴(kuò)容問題實(shí)例詳解
這篇文章主要介紹了Java ArrayList擴(kuò)容問題實(shí)例詳解,分享了相關(guān)代碼示例,小編覺得還是挺不錯(cuò)的,具有一定借鑒價(jià)值,需要的朋友可以參考下2018-02-02