久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

Springboot整合Mybatispuls的實(shí)例詳解

瀏覽:85日期:2023-04-09 13:11:14

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源碼

Springboot整合Mybatispuls的實(shí)例詳解

實(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)!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 子洲县| 嘉义市| 资溪县| 蒙城县| 东城区| 永川市| 南岸区| 太仆寺旗| 夹江县| 昭觉县| 西安市| 伊通| 平江县| 德保县| 奎屯市| 安丘市| 北京市| 桐城市| 香河县| 淮北市| 凭祥市| 卓尼县| 肇源县| 鄢陵县| 二手房| 尚义县| 高安市| 隆昌县| 迁西县| 乳源| 偏关县| 石嘴山市| 谢通门县| 大洼县| 洛川县| 呼玛县| 五华县| 房产| 聊城市| 普安县| 安吉县|