MyBatis-Plus
Ezerbel
这个作者很懒,什么都没留下…
展开
-
MyBatis-Plus 主键策略
雪花算法如果子类中也指定了主键策略,则子类中设定会覆盖父类。官方定义/** * 生成ID类型枚举类 * * @author hubin * @since 2015-11-10 */@Getterpublic enum IdType { /** * 数据库ID自增 */ AUTO(0), /** * 该类型为未设置主键类型(注解里等于跟随全局,全局里约等于 INPUT) */ NONE(1), /**原创 2020-11-25 18:22:30 · 244 阅读 · 0 评论 -
MyBatis-Plus学习-part12 mp代码生成器之详细版
package com.ezerbel.grain.service.edu;import com.baomidou.mybatisplus.annotation.DbType;import com.baomidou.mybatisplus.annotation.FieldFill;import com.baomidou.mybatisplus.annotation.IdType;import com.baomidou.mybatisplus.core.exceptions.MybatisPlusE原创 2020-09-16 14:49:40 · 114 阅读 · 0 评论 -
MyBatis-Plus学习-part11 分页节流仅返回指定数据列
文件结构分页插件配置这里使用的是SpringBootpackage com.ezerbel.mybatis_plus.config;import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration原创 2020-09-16 07:37:45 · 406 阅读 · 0 评论 -
MyBatis-Plus学习-part10 公共字段的填充
标识公共字段及其策略//插入和更新时使用填充策略@TableField(fill=FieldFill.INSERT_UPDATE)private String name;自定义公共字段处理器@Componentpublic class MyMetaObjHandler extends MetaObjectHandler{ /** * 插入操作自动填充 */ @Override public void insertFill(MetaObject metaObject) {原创 2020-08-26 15:53:43 · 107 阅读 · 0 评论 -
MyBatis-Plus学习-part9 逻辑删除
定义为了测试或者"备份"珍贵数据,可以使用假删除,使用一个字段标识这条数据是否处于删除状态,从此以后,删除操作变为更新删除标识的值。数据表增加标识字段实体类public class User{ @TableField(exist=false) private static final long serialVersionUID = 8989393974992291293L; private Integer id; @TableField(fill=FieldFill.INSER原创 2020-08-26 15:45:24 · 116 阅读 · 0 评论 -
MyBatis-Plus学习-part8 定义全局操作
AutoSqlInjectorBaseMapper提供了17个常用的方法,但是有些需求可能无法很好的实现,MP提供了自定义全局操作来解决这个问题。mapper接口中定义方法public interface EmployeeMapper extends BaseMapper<Employee> { // 1.在Mapper接口中定义相关的CRUD方法 // 2.扩展AutoSqlInjector inject方法,实现Mapper接口中方法要注入的SQL // 3.在MP的全局策略中,原创 2020-08-26 15:35:49 · 130 阅读 · 0 评论 -
MyBatis-Plus学习-part7 分页插件、乐观锁插件等
pom<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframewo原创 2020-08-26 15:27:24 · 106 阅读 · 0 评论 -
MyBatis-Plus学习-part6 代码生成器
添加依赖 <!-- 代码生成器依赖开始 --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity-engine-core</artifactId> <version>2.0</version> </dependency> <dependency> <groupI原创 2020-08-26 15:19:50 · 70 阅读 · 0 评论 -
MyBatis-Plus学习-part5 使用AR模式
entity/** * java Bean * @author Administrator * *///@TableName(value="tb_employee")public class Employee extends Model<Employee>{ //@TableId(value="id",type=IdType.AUTO)// value 指定数据库中对应列名, type 主键使用的策略 private Integer id; @TableField(v原创 2020-08-26 15:12:46 · 189 阅读 · 0 评论 -
MyBatis-Plus学习-part4 使用条件构造器Wrapper等
条件构造器MP通过EntityWrapper(简称EW,MP封装的一个查询条件构造器 )或者Condition(与EW类似)来让用户自由的构建查询条件,简便快捷,没有额外的负担。条件参数https://baomidou.com/guide/wrapper.html#abstractwrapperallEq ,eq,ne,gt,ge,lt ,lebetween, notBetween,like,notLike:notLike("name", "王")--->name not like '原创 2020-08-26 15:05:10 · 335 阅读 · 0 评论 -
MyBatis-Plus学习-part3 通用CRUD
Mapper/** * @author Ezerbel * * 基于Mybatis: 在Mapper接口中编写CRUD相关方法,提供Mapper接口所对应的SQL映射文件以及方法对应的SQL语句 * 基于MP: 让XxxMapper接口继承BaseMapper接口即可。 */public interface EmployeeMapper extends BaseMapper<Employee>{}插入@Testpublic void testCommonInsert()原创 2020-08-26 14:37:47 · 77 阅读 · 0 评论 -
MyBatis-Plus学习-part2 MP获取自增主键值
MyBatis获取自增主键与非自增主键需要通过useGeneratedKeys 以及 keyProperty <!-- 在mysql数据库中,每张表的自增列只能有一个 --> <!-- useGeneratedKeys 使用自动生成的主键,keyProperty将自动生成的主键映射给那个属性 --> <insert id="insertEmployee" useGeneratedKeys="true" keyProperty="id">原创 2020-08-24 13:12:40 · 1315 阅读 · 0 评论 -
MyBatis-Plus学习-part1 Spring整合MP并实现插入
文件结构pom<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</mod原创 2020-08-24 10:37:34 · 233 阅读 · 0 评论