有一个查询活动的方法需要把所属组织放到实体里面,如果自定义一个resultMap的话,分页需要重新实现,所以集成了mprelation
添加依赖
<!--mprelation,mybatis-plus一对多插件-->
<dependency>
<groupId>com.github.dreamyoung</groupId>
<artifactId>mprelation</artifactId>
<version>0.0.3.2-RELEASE</version>
</dependency>
添加AutoMapperConfig
配置类
package com.school.demo.config;
import com.github.dreamyoung.mprelation.AutoMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @program: demo
* @description:
* @author: Charlotte
* @create: 2021-04-25 09:13
**/
@Configuration
public class AutoMapperConfig {
@Bean
public AutoMapper autoMapper() {
return new AutoMapper(new String[] { "com.school.demo.model.auto.Activities" }); //配置实体类所在目录(可多个,暂时不支持通过符*号配置)
}
}
配置实体类
@TableField(exist = false)
@ManyToOne
private Organization organization;//组织在查询之后重新添加
之后继续使用mybatis-plus的各种方法可以正常使用,例如分页之类