目录
在指定的时间,执行相应的业务代码。
比如: OSS文件系统服务器,会产生大量冗余文件。定时删除冗余文件【凌晨2~3点】。
比如: 下单后半个未支付--取消订单。
(1)引入定时器依赖。
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-quartzartifactId>
- dependency>
(2)编写定义任务代码。
- @Component//交给Spring管理
- public class Scheduling {
-
- //直接运行,任务代码cron:定义定时任务的规则 https://www.pppet.net/
- @Scheduled(cron = "0/1 * * * * ? ")
- public void test01(){
- System.out.println("啦啦啦啦");
- }
-
- }
cron = "0/1 * * * * ? "生成的方式是使用下述链接
在线Cron表达式生成器Cron表达式在线生成器,方便的在线生成各类Cron表达式,并可以将Cron表达式的可视化双向解析和生成.https://www.pppet.net/(3) 开启定时任务的注解

MyBatis-Plus (opens new window)(简称 MP)是一个 MyBatis (opens new window)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。单表操作的都不需要自己在写sql语句。
无侵入:只做增强不做改变,引入它不会对现有工程产生影响,如丝般顺滑
损耗小:启动即会自动注入基本 CURD,性能基本无损耗,直接面向对象操作
强大的 CRUD 操作:内置通用 Mapper、通用 Service,仅仅通过少量配置即可实现-==单表大部分 CRUD 操作==,更有强大的==条件构造器[条件封装成一个条件类]==,满足各类使用需求
支持 Lambda 形式调用:通过 Lambda 表达式,方便的编写各类查询条件,无需再担心字段写错
支持主键自动生成:支持多达 4 种主键策略(内含分布式唯一 ID 生成器 - Sequence),可自由配置,完美解决主键问题
支持 ActiveRecord 模式:支持 ActiveRecord 形式调用,实体类只需继承 Model 类即可进行强大的 CRUD 操作
支持自定义全局通用操作:支持全局通用方法注入( Write once, use anywhere )
内置代码生成器:采用代码或者 Maven 插件可快速生成 Mapper 、 Model 、 Service 、 Controller 层代码,支持模板引擎,更有超多自定义配置等您来使用
内置分页插件:基于 MyBatis 物理分页,开发者无需关心具体操作,配置好插件之后,写分页等同于普通 List 查询。
分页插件支持多种数据库:支持 MySQL、MariaDB、Oracle、DB2、H2、HSQL、SQLite、Postgre、SQLServer 等多种数据库.
内置性能分析插件:可输出 SQL 语句以及其执行时间,建议开发测试时启用该功能,能快速揪出慢查询
内置全局拦截插件:提供全表 delete 、 update 操作智能分析阻断,也可自定义拦截规则,预防误操作.
快速开始 | MyBatis-Plus
(1)创建数据库和表
- DROP TABLE IF EXISTS user;
-
- CREATE TABLE user
- (
- id BIGINT(20) NOT NULL COMMENT '主键ID',
- name VARCHAR(30) NULL DEFAULT NULL COMMENT '姓名',
- age INT(11) NULL DEFAULT NULL COMMENT '年龄',
- email VARCHAR(50) NULL DEFAULT NULL COMMENT '邮箱',
- PRIMARY KEY (id)
- );
- DELETE FROM user;
-
- INSERT INTO user (id, name, age, email) VALUES
- (1, 'Jone', 18, 'test1@baomidou.com'),
- (2, 'Jack', 20, 'test2@baomidou.com'),
- (3, 'Tom', 28, 'test3@baomidou.com'),
- (4, 'Sandy', 21, 'test4@baomidou.com'),
(2)依赖
-
-
- <dependency>
- <groupId>com.baomidougroupId>
- <artifactId>mybatis-plus-boot-starterartifactId>
- <version>3.5.1version>
- dependency>
(3)创建实体类
- @Data
- @AllArgsConstructor
- @NoArgsConstructor
- //若表名不一致@TableName(value = "")
- public class User {
- @TableId(value = "id",type = IdType.AUTO)
- private Integer id;
-
- //如果属性和列名不一致 @TableField(value = )
-
- private String name;
-
- private Integer age;
-
- private String email;
-
- @TableField(fill = FieldFill.INSERT)
- private LocalDateTime gmtCreated;
-
- @TableField(fill = FieldFill.UPDATE)
- private LocalDateTime gmtUpdated;
-
- @TableLogic//逻辑列
- private Integer isdeleted;
-
- @TableField(exist = false)
- private Dept dept;
- }
(4)dao
- //BaseMapper提供了单表的所有操作 crud
- @Mapper
- public interface UserMapper extends BaseMapper
{ - IPage
selectUserWithDept(IPage page, @Param("ew") Wrapper wrapper) ; - }
(5)测试
- @Autowired
- private UserMapper userMapper;
- @Test
- void contextLoads() {
- User user = userMapper.selectById(1);
- System.out.println(user);
- }
注意要在实体类对应的type编写:
主键mp提供相应的生成策略
AUTO,递增策略,如果使用该策略必须要求数据表的列也是递增。
NONE,没有策略,必须人为的输入id值,若不输入则会产生负数
INPUT,没有策略,必须人为的输入id值
ASSIGN_ID,随机生成一个Long类型的值。该值一定是唯一。而且每次生成都不会相同。算法:雪花算法。 适合分布式主键。
ASSIGN_UUID,随机产生一个String类型的值。该值也是唯一的。
- /**
- * 主键mp提供相应的生成策略:
- * AUTO(0),递增策略,如果使用该策略必须要求数据表的列也是递增。
- * NONE(1),没有策略,必须人为的输入id值,若不输入则会产生负数
- * INPUT(2),没有策略,必须人为的输入id值
- * ASSIGN_ID(3), 随机生成一个Long类型的值。该值一定是唯一。而且每次生成都不会相同。算法:雪花算法。 适合分布式主键。
- * ASSIGN_UUID(4); 随机产生一个String类型的值。该值也是唯一的。
- */
-
- @Test
- public void insert(){
- User user=new User();
- user.setName("小樱");
- user.setEmail("test4@1232243");
- user.setAge(17);
- System.out.println("添加前=============="+user);
- int insert = userMapper.insert(user);//mp会把生成的主键值复制给对象??
- System.out.println("添加后=============="+user);
- System.out.println(insert);
-
-
- }
- /**
- * 实际开发中: 我们的删除可能是逻辑删除。所谓的逻辑删除就是修改功能。把某个列修改以删除的状态值。
- * 只对自动注入的 sql 起效:
- * 插入: 不作限制---
- * 查找: 追加 where 条件过滤掉已删除数据,且使用 wrapper.entity 生成的 where 条件会忽略该字段
- * 更新: 追加 where 条件防止更新到已删除数据,且使用 wrapper.entity 生成的 where 条件会忽略该字段
- * 删除: 转变为 更新
- * (1)增加一个逻辑字段: isdeleted 0表示未删除 1表示删除.
- * (2)实体类上的字段添加 @TableLogic.
- */
- @Test
- public void testDelete(){
- int i = userMapper.deleteById(6);
- //根据主键删除
- System.out.println(i);
- }
- @Test
- public void testSelectByCondition(){
- //Wrapper:封装了关于查询的各种条件方法。有三个子类最常用: QueryWrapper查询条件 UpdateWrapper修改条件 LambdaQueryWrapper查询使用lambda表达式条件
- QueryWrapper
wrapper=new QueryWrapper<>(); - wrapper.between("age",15,28);//年龄的要查找的范围值
- wrapper.select("name","age");//选择select *的*中要查询的内容
- wrapper.like("name","a");//名字的模糊查询
- System.out.println(userMapper.selectList(wrapper));//要同时满足以上三个条件,才可以输出
- }
- @Test
- public void testSelectOne(){
- QueryWrapper
wrapper=new QueryWrapper<>(); - wrapper.eq("username","");
- wrapper.eq("password","");
- User user = userMapper.selectOne(wrapper);
- }
- /**
- * (1)添加分页拦截器
- * (2)调用分页方法
- */
- @Test
- public void testPage(){
- //P page, 分页对象 Page
- // @Param("ew") Wrapper
queryWrapper - Page
page=new Page<>(1,3); - userMapper.selectPage(page,null);//把查询的结果自动封装到Page对象中
- System.out.println("总页码"+page.getPages());
- System.out.println("总条数"+page.getTotal());
- System.out.println("当前页记录"+page.getRecords());
- }
- /**
- * 联表查询 使用mp的分页功能。
- */
- @Test
- public void testLianBiao(){
- //P page, 分页对象 Page
- // @Param("ew") Wrapper
queryWrapper - Page
page=new Page<>(1,3); - QueryWrapper
wrapper=new QueryWrapper<>(); - wrapper.eq("name","小樱");
- IPage
userIPage = userMapper.selectUserWithDept(page, wrapper); - System.out.println("总页码"+page.getPages());
- System.out.println("总条数"+page.getTotal());
- System.out.println("当前页记录"+page.getRecords());
- }
- //BaseMapper提供了单表的所有操作 crud
- @Mapper
- public interface UserMapper extends BaseMapper
{ - IPage
selectUserWithDept(IPage page, @Param("ew") Wrapper wrapper) ; - }
- <mapper namespace="com.qy151.dao.UserMapper">
- <resultMap id="baseMapper" type="com.qy151.entity.User" autoMapping="true">
- <id column="id" property="id"/>
- <association property="dept" javaType="com.qy151.entity.Dept" autoMapping="true">
- <id column="did" property="id"/>
- association>
- resultMap>
- <select id="selectUserWithDept" resultMap="baseMapper">
- select * from user u join tbl_dept d on u.did=d.did where isdeleted=0
- <if test="ew!=null">
- and ${ew.sqlSegment}
- if>
- select>
- mapper>
- <dependency>
- <groupId>com.baomidougroupId>
- <artifactId>mybatis-plus-generatorartifactId>
- <version>3.4.1version>
- dependency>
- <dependency>
- <groupId>org.apache.velocitygroupId>
- <artifactId>velocity-engine-coreartifactId>
- <version>2.3version>
- dependency>
-
- <dependency>
- <groupId>org.freemarkergroupId>
- <artifactId>freemarkerartifactId>
- <version>2.3.30version>
- dependency>
- package com.qy151wd.autiomp;
-
- import com.baomidou.mybatisplus.core.toolkit.StringPool;
- import com.baomidou.mybatisplus.generator.AutoGenerator;
- import com.baomidou.mybatisplus.generator.InjectionConfig;
- import com.baomidou.mybatisplus.generator.config.*;
- import com.baomidou.mybatisplus.generator.config.po.TableInfo;
- import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
- import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
-
- import java.util.ArrayList;
- import java.util.List;
-
- // 演示例子,执行 main 方法控制台输入模块表名回车自动生成对应项目目录中
- public class CodeGenerator {
-
- /**
- *
- * 读取控制台内容
- *
- */
- public static void main(String[] args) {
- // 代码生成器
- AutoGenerator mpg = new AutoGenerator();
-
- // 全局配置
- GlobalConfig gc = new GlobalConfig();
- gc.setOutputDir("./src/main/java");
- gc.setAuthor("wd");
- gc.setOpen(false);
- gc.setSwagger2(true); //实体属性 Swagger2 注解
- mpg.setGlobalConfig(gc);
-
- // 数据源配置
- DataSourceConfig dsc = new DataSourceConfig();
- dsc.setUrl("jdbc:mysql://localhost:3306/mp?serverTimezone=Asia/Shanghai");
- // dsc.setSchemaName("public");
- dsc.setDriverName("com.mysql.cj.jdbc.Driver");
- dsc.setUsername("root");
- dsc.setPassword("123456");
- mpg.setDataSource(dsc);
-
- // 包配置
- PackageConfig pc = new PackageConfig();
- pc.setModuleName("autiomp");
- pc.setParent("com.qy151wd");
- mpg.setPackageInfo(pc);
-
- // 自定义配置
- InjectionConfig cfg = new InjectionConfig() {
- @Override
- public void initMap() {
- // to do nothing
- }
- };
-
- // 如果模板引擎是 freemarker
- String templatePath = "/templates/mapper.xml.ftl";
- // 如果模板引擎是 velocity
- // String templatePath = "/templates/mapper.xml.vm";
-
- // 自定义输出配置
- List
focList = new ArrayList<>(); - // 自定义配置会被优先输出
- focList.add(new FileOutConfig(templatePath) {
- @Override
- public String outputFile(TableInfo tableInfo) {
- tableInfo.setName(tableInfo.getName().replace("tbl_",""));
- //tableInfo.setEntityName(tableInfo.getEntityName().replace("Tbl",""));
- tableInfo.setControllerName(tableInfo.getControllerName().replace("Tbl",""));
- tableInfo.setServiceName(tableInfo.getServiceName().replace("Tbl",""));
- tableInfo.setServiceImplName(tableInfo.getServiceImplName().replace("Tbl",""));
- tableInfo.setMapperName(tableInfo.getMapperName().replace("Tbl",""));
- tableInfo.setXmlName(tableInfo.getXmlName().replace("Tbl",""));
- // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
- return "./src/main/resources/mapper/"
- + "/" + tableInfo.getEntityName().replace("Tbl","") + "Mapper" + StringPool.DOT_XML;
- }
- });
- /*
- cfg.setFileCreate(new IFileCreate() {
- @Override
- public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
- // 判断自定义文件夹是否需要创建
- checkDir("调用默认方法创建的目录,自定义目录用");
- if (fileType == FileType.MAPPER) {
- // 已经生成 mapper 文件判断存在,不想重新生成返回 false
- return !new File(filePath).exists();
- }
- // 允许生成模板文件
- return true;
- }
- });
- */
- cfg.setFileOutConfigList(focList);
- mpg.setCfg(cfg);
-
- // 配置模板
- TemplateConfig templateConfig = new TemplateConfig();
-
- // 配置自定义输出模板
- //指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
- // templateConfig.setEntity("templates/entity2.java");
- // templateConfig.setService();
- // templateConfig.setController();
-
- templateConfig.setXml(null);
- mpg.setTemplate(templateConfig);
-
- // 策略配置
- StrategyConfig strategy = new StrategyConfig();
- strategy.setNaming(NamingStrategy.underline_to_camel);
- strategy.setColumnNaming(NamingStrategy.underline_to_camel);
- strategy.setEntityLombokModel(true);
- strategy.setRestControllerStyle(true);
- // 公共父类
- // 写于父类中的公共字段
- strategy.setControllerMappingHyphenStyle(true);
- mpg.setStrategy(strategy);
- mpg.setTemplateEngine(new FreemarkerTemplateEngine());
- mpg.execute();
- }
-
- }
混合使用mp代码生成器+swagger+联表查询

- <dependencies>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-webartifactId>
- dependency>
-
-
- <dependency>
- <groupId>com.baomidougroupId>
- <artifactId>mybatis-plus-boot-starterartifactId>
- <version>3.4.2version>
- dependency>
-
-
- <dependency>
- <groupId>com.baomidougroupId>
- <artifactId>mybatis-plus-generatorartifactId>
- <version>3.4.1version>
- dependency>
- <dependency>
- <groupId>org.apache.velocitygroupId>
- <artifactId>velocity-engine-coreartifactId>
- <version>2.3version>
- dependency>
- <dependency>
- <groupId>org.freemarkergroupId>
- <artifactId>freemarkerartifactId>
- <version>2.3.30version>
- dependency>
-
-
- <dependency>
- <groupId>com.spring4allgroupId>
- <artifactId>swagger-spring-boot-starterartifactId>
- <version>1.9.1.RELEASEversion>
- dependency>
- <dependency>
- <groupId>com.github.xiaoymingroupId>
- <artifactId>swagger-bootstrap-uiartifactId>
- <version>1.7.8version>
- dependency>
-
- <dependency>
- <groupId>mysqlgroupId>
- <artifactId>mysql-connector-javaartifactId>
- <scope>runtimescope>
- dependency>
- <dependency>
- <groupId>org.projectlombokgroupId>
- <artifactId>lombokartifactId>
- <optional>trueoptional>
- dependency>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-testartifactId>
- <scope>testscope>
- dependency>
- dependencies>
- // 演示例子,执行 main 方法控制台输入模块表名回车自动生成对应项目目录中
- public class CodeGenerator {
-
- /**
- *
- * 读取控制台内容
- *
- */
- public static void main(String[] args) {
- // 代码生成器
- AutoGenerator mpg = new AutoGenerator();
-
- // 全局配置
- GlobalConfig gc = new GlobalConfig();
- gc.setOutputDir("./src/main/java");
- gc.setAuthor("wd");
- gc.setOpen(false);
- gc.setSwagger2(true); //实体属性 Swagger2 注解
- mpg.setGlobalConfig(gc);
-
- // 数据源配置
- DataSourceConfig dsc = new DataSourceConfig();
- dsc.setUrl("jdbc:mysql://localhost:3306/mp?serverTimezone=Asia/Shanghai");
- // dsc.setSchemaName("public");
- dsc.setDriverName("com.mysql.cj.jdbc.Driver");
- dsc.setUsername("root");
- dsc.setPassword("123456");
- mpg.setDataSource(dsc);
-
- // 包配置
- PackageConfig pc = new PackageConfig();
- pc.setModuleName("autiomp");
- pc.setParent("com.qy151wd");
- mpg.setPackageInfo(pc);
-
- // 自定义配置
- InjectionConfig cfg = new InjectionConfig() {
- @Override
- public void initMap() {
- // to do nothing
- }
- };
-
- // 如果模板引擎是 freemarker
- String templatePath = "/templates/mapper.xml.ftl";
- // 如果模板引擎是 velocity
- // String templatePath = "/templates/mapper.xml.vm";
-
- // 自定义输出配置
- List
focList = new ArrayList<>(); - // 自定义配置会被优先输出
- focList.add(new FileOutConfig(templatePath) {
- @Override
- public String outputFile(TableInfo tableInfo) {
- tableInfo.setName(tableInfo.getName().replace("tbl_",""));
- //tableInfo.setEntityName(tableInfo.getEntityName().replace("Tbl",""));
- tableInfo.setControllerName(tableInfo.getControllerName().replace("Tbl",""));
- tableInfo.setServiceName(tableInfo.getServiceName().replace("Tbl",""));
- tableInfo.setServiceImplName(tableInfo.getServiceImplName().replace("Tbl",""));
- tableInfo.setMapperName(tableInfo.getMapperName().replace("Tbl",""));
- tableInfo.setXmlName(tableInfo.getXmlName().replace("Tbl",""));
- // 自定义输出文件名 , 如果你 Entity 设置了前后缀、此处注意 xml 的名称会跟着发生变化!!
- return "./src/main/resources/mapper/"
- + "/" + tableInfo.getEntityName().replace("Tbl","") + "Mapper" + StringPool.DOT_XML;
- }
- });
- /*
- cfg.setFileCreate(new IFileCreate() {
- @Override
- public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
- // 判断自定义文件夹是否需要创建
- checkDir("调用默认方法创建的目录,自定义目录用");
- if (fileType == FileType.MAPPER) {
- // 已经生成 mapper 文件判断存在,不想重新生成返回 false
- return !new File(filePath).exists();
- }
- // 允许生成模板文件
- return true;
- }
- });
- */
- cfg.setFileOutConfigList(focList);
- mpg.setCfg(cfg);
-
- // 配置模板
- TemplateConfig templateConfig = new TemplateConfig();
-
- // 配置自定义输出模板
- //指定自定义模板路径,注意不要带上.ftl/.vm, 会根据使用的模板引擎自动识别
- // templateConfig.setEntity("templates/entity2.java");
- // templateConfig.setService();
- // templateConfig.setController();
-
- templateConfig.setXml(null);
- mpg.setTemplate(templateConfig);
-
- // 策略配置
- StrategyConfig strategy = new StrategyConfig();
- strategy.setNaming(NamingStrategy.underline_to_camel);
- strategy.setColumnNaming(NamingStrategy.underline_to_camel);
- strategy.setEntityLombokModel(true);
- strategy.setRestControllerStyle(true);
- // 公共父类
- // 写于父类中的公共字段
- strategy.setControllerMappingHyphenStyle(true);
- mpg.setStrategy(strategy);
- mpg.setTemplateEngine(new FreemarkerTemplateEngine());
- mpg.execute();
- }
-
- }
- @SpringBootApplication
- @EnableSwagger2
- @MapperScan(value = "com.qy151wd.autiomp.mapper")
- public class AutiompApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(AutiompApplication.class, args);
- }
-
- }
- @Configuration
- public class MybatisPlusConfig {
-
- /**
- * 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
- */
- @Bean
- public MybatisPlusInterceptor mybatisPlusInterceptor() {
- MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
- interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
- return interceptor;
- }
-
- }
- @Slf4j
- @Component
- public class MyMetaObjectHandler implements MetaObjectHandler {
-
- @Override//当添加时自动填充的值
- public void insertFill(MetaObject metaObject) {
- log.info("start insert fill ....");
-
- this.strictInsertFill(metaObject, "gmtCreated", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
- }
-
- @Override //当修改时自动填充的值d
- public void updateFill(MetaObject metaObject) {
- log.info("start update fill ....");
-
- this.strictUpdateFill(metaObject, "gmtUpdated", () -> LocalDateTime.now(), LocalDateTime.class); // 起始版本 3.3.3(推荐)
-
- }
- }
- @Data
- @EqualsAndHashCode(callSuper = false)
- @ApiModel(value="TblDept对象", description="")
- @TableName(value = "tbl_dept")
- public class TblDept implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @ApiModelProperty(value = "部门编号")
- @TableId(value = "did", type = IdType.AUTO)
- private Integer did;
-
- @ApiModelProperty(value = "部门名称")
- private String dName;
-
-
- }
- @Data
- @EqualsAndHashCode(callSuper = false)
- @ApiModel(value="User对象", description="")
- public class User implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @ApiModelProperty(value = "主键ID")
- @TableId(value = "id", type = IdType.AUTO)
- private Integer id;
-
- @ApiModelProperty(value = "姓名")
- private String name;
-
- @ApiModelProperty(value = "年龄")
- private Integer age;
-
- @ApiModelProperty(value = "邮箱")
- private String email;
-
- @ApiModelProperty(value = "逻辑列0代表未删除,1代表已删除")
- @TableLogic//逻辑列
- private Boolean isdeleted;
-
- @ApiModelProperty(value = "创建时间")
- @TableField(fill = FieldFill.INSERT)
- private LocalDateTime gmtCreated;
-
- @ApiModelProperty(value = "更新时间")
- @TableField(fill = FieldFill.UPDATE)
- private LocalDateTime gmtUpdated;
-
- @ApiModelProperty(value = "部门id")
- @TableField(exist = false)
- private TblDept tblDept;
-
-
- }
添加联表查询后进行分页输出:UserMapper
- public interface UserMapper extends BaseMapper
{ - IPage
selectUserWithDept(IPage page, @Param("ew") Wrapper wrapper) ; - }
添加联表查询:UserMapper.xml
- mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.qy151wd.autiomp.mapper.UserMapper">
- <resultMap id="baseMapper" type="com.qy151wd.autiomp.entity.User" autoMapping="true">
- <id column="id" property="id"/>
- <result property="gmtCreated" column="gmt_created"/>
- <result property="gmtUpdated" column="gmt_updated"/>
- <association property="tblDept" javaType="com.qy151wd.autiomp.entity.TblDept" autoMapping="true">
- <id column="deptId" property="did"/>
- association>
- resultMap>
- <sql id="allChose">
- id,name,age,email,isdeleted,gmt_created,gmt_updated,u.did,d.did deptId,d.dname
- sql>
- <select id="selectUserWithDept" resultMap="baseMapper">
- select <include refid="allChose"/> from user u join tbl_dept d on u.did=d.did where isdeleted=0
- <if test="ew!=null">
- and ${ew.sqlSegment}
- if>
- select>
-
- mapper>
- spring.datasource.password=123456
- spring.datasource.username=root
- spring.datasource.url=jdbc:mysql://localhost:3306/mp?serverTimezone=Asia/Shanghai
- spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
-
- //sql日志
- mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
-
- #指定映射文件的路径
- mybatis.mapper-locations=classpath:mapper/*Mapper.xml
-
- spring.mvc.pathmatch.matching-strategy=ant_path_matcher