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ù)庫(kù)不同使用 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. 基于javaweb+jsp實(shí)現(xiàn)企業(yè)車輛管理系統(tǒng)2. XML在語(yǔ)音合成中的應(yīng)用3. php使用正則驗(yàn)證密碼字段的復(fù)雜強(qiáng)度原理詳細(xì)講解 原創(chuàng)4. uni-app結(jié)合.NET 7實(shí)現(xiàn)微信小程序訂閱消息推送5. asp.net core 認(rèn)證和授權(quán)實(shí)例詳解6. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢、排序、分頁(yè)7. jscript與vbscript 操作XML元素屬性的代碼8. .NET中實(shí)現(xiàn)對(duì)象數(shù)據(jù)映射示例詳解9. ASP.NET Core 7 Razor Pages項(xiàng)目發(fā)布到IIS的詳細(xì)過(guò)程10. 如何使用ASP.NET Core 配置文件
