mybatis-plus.global-config.db-config.logic-delete-value=1 mybatis-plus.global-config.db-config.logic-not-delete-value=0 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 3.entity @Data public class User { private Long id; private String name; private Integer age; private St...
接下来,我们可以通过静态工具Db的insert方法插入数据。以下是一个示例: import com.baomidou.mybatisplus.core.toolkit.Db;import com.baomidou.mybatisplus.core.toolkit.Wrappers;import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;public class StudentService {public void insertStudent(Student student) {in...
前面介绍了两种 Mybatis 的数据源配置,当然也少不了 mybatis-plus MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,既然做增强,那多数据源这种硬性场景,肯定是有非常简单的解决方案的 本文将实例演示 Mybatis-Plus 多数据源的配...
1. 准备 准备两张表,用于测试 代码语言:txt 复制 CREATE TABLE `userT0` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(20) NOT NULL DEFAULT '' COMMENT '用户名', `pwd` varchar(26) NOT NULL DEFAULT '' COMMENT '密码', `isDeleted` tinyint(1) NOT NULL DEFAULT '0',...
开发过程中,经常会遇到这两种场景,第一个是业务需求需要操作多个DB场景,比如:下单时,需要从用户库中查询用户信息,同时需要向订单库里插入一条订单;另一个是读写分离场景,这个大家熟悉的不能在熟了,就不用过多介绍了。这两个场景就是典型的多数据源访问。
有的时候Service之间也会相互调用,为了避免出现循环依赖问题,MybatisPlus提供一个静态工具类:Db,其中的一些静态方法与IService中方法签名基本一致,也可以帮助我们实现CRUD功能: 示例: @Testvoid testDbGet() {User user = Db.getById(1L, User.class);System.out.println(user);}@Testvoid testDbList() {// ...
USE mybatisdb; -- --- -- Table structure for user -- --- DROP TABLE IF EXISTS user; CREATE TABLE user ( id int(11) NOT NULL AUTO_INCREMENT, username varchar(32) NOT NULL COMMENT '用户名称', birthday datetime DEFAULT NULL COMMENT '生日', sex char(1) DEFAULT NULL COMMENT...
@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor(){ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.H2)); return interceptor;} 接下来改造上面的代码,调用selectJoinPage()方法:public void page() { ...
db-config: # 配置MyBatis-Plus操作表的默认前缀 table-prefix: "t_" # 配置MyBatis-Plus的主键策略 id-type: auto # 配置MyBatis日志 configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 6、@TableField MyBatis-Plus在执行SQL语句时,要保证实体类中的属性名和表中的字段名一致,否则就会...