Python 官方文档:入门教程 => 点击学习
目录mybatis-Plus介绍简介特性(官网提供)一、引入POM依赖二、配置文件application.yml三、编写表映射实体类四、编写Mapper五、测试Controller六
MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.1</version>
</dependency>
spring:
datasource:
url: jdbc:mysql://172.26.0.296:3306/he?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root
passWord: P0de
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
@TableName("sys_user") // 指定表名
public class UserEntity {
private String id;
private String username;
public String id() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
简单写个注解sql
public interface TestMapper extends BaseMapper<UserEntity> {
@Select("select id from sys_user limit 1")
String getId();
}
测试通过:QueryWrapper方式查询 + 注解方式查询。
@RestController
@RequestMapping("/wechat/portal")
public class WechatController {
@Autowired
private TestMapper testMapper;
@GetMapping("/test")
public String getTest() {]
// QueryWrapper方式查询
QueryWrapper<UserEntity> queryWrapper = new QueryWrapper<>();
List<UserEntity> userEntities = testMapper.selectList(queryWrapper);
System.out.println("userEntities --- " + userEntities);
// 注解方式查询
String id = testMapper.getId();
System.out.println("id ---" + id);
return userEntities.toString();
}
}
通过@MapperScan指定mapper所在包路径。
@SpringBootApplication
@MapperScan("org.jeecg.modules.mp.mapper") // 指定mapper包路径
public class WxMpDemoApplication {
public static void main(String[] args) {
SpringApplication.run(WxMpDemoApplication.class, args);
}
}
到此这篇关于springboot四步集成mybatisplus的文章就介绍到这了,更多相关springboot集成mybatisplus内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: springboot集成mybatisplus的详细步骤
本文链接: https://www.lsjlt.com/news/169761.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0