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=rootspring.datasource.password=rootspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driverspring.datasource.url=jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTCserver.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ù)庫不同使用 private String password; private Integer Authority;}
mapper接口編寫繼承BaseMapper<這里為實(shí)體類>
@org.apache.ibatis.annotations.Mapper//讓Spring容器掃描該類為Mapper@Repositorypublic interface Mapper extends BaseMapper<Users> {}
BaseMapper源碼
實(shí)現(xiàn)接口方法
@RestControllerpublic 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)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. Python調(diào)用接口合并Excel表代碼實(shí)例2. .net如何優(yōu)雅的使用EFCore實(shí)例詳解3. Python快速將ppt制作成配音視頻課件的操作方法4. ASP.Net Core對(duì)USB攝像頭進(jìn)行截圖5. 一文透徹詳解.NET框架類型系統(tǒng)設(shè)計(jì)要點(diǎn)6. 通過CSS數(shù)學(xué)函數(shù)實(shí)現(xiàn)動(dòng)畫特效7. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢、排序、分頁8. 通過Ajax方式綁定select選項(xiàng)數(shù)據(jù)的實(shí)例9. ASP.NET MVC實(shí)現(xiàn)橫向展示購物車10. ajax動(dòng)態(tài)加載json數(shù)據(jù)并詳細(xì)解析
