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)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. ASP基礎(chǔ)知識VBScript基本元素講解2. Python 利用Entrez庫篩選下載PubMed文獻(xiàn)摘要的示例3. Python 合并拼接字符串的方法4. Python 制作查詢商品歷史價格的小工具5. Python 如何調(diào)試程序崩潰錯誤6. Python sublime安裝及配置過程詳解7. python使用jenkins發(fā)送企業(yè)微信通知的實(shí)現(xiàn)8. Linux刪除系統(tǒng)自帶版本Python過程詳解9. ASP.NET MVC使用jQuery ui的progressbar實(shí)現(xiàn)進(jìn)度條10. Python3 json模塊之編碼解碼方法講解

網(wǎng)公網(wǎng)安備