1、依赖mybatis-plus
<dependency>
<groupId>com.github.jeffreyning</groupId>
<artifactId>mybatisplus-plus</artifactId>
<version>1.5.1-RELEASE</version>
</dependency>
2、实体类,联合主键字段上使用@MppMultiId注解
@TableName("etl_job")
public class Job implements Serializable {
private static final long serialVersionUID=1L;
@MppMultiId // 复合主键
private String etlSystem;
@MppMultiId // 复合主键
private String etlJob;
}
3.Mapper类,继承MppBaseMapper
public interface JobMapper extends MppBaseMapper<Job> { }
4、mapper.xml
<resultMap id="BaseResultMap" type="com.dd.study.beans.Job">
<id column="etl_system" property="etlSystem" />
<id column="etl_job" property="etlJob" />
</resultMap>
6.Service
public interface JobService extends IMppService<Job> { }
7、ServiceImpl
@Service public class JobServiceImpl extends MppServiceImpl<JobMapper, Job> implements JobService { }
8、应用复合主键相关的操作
jobService.saveOrUpdateByMultiId(job);
9、在启动类加上@EnableMPP