1.mybatis-plus 版本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
< dependency > < groupId >com.github.jeffreyning</ groupId > < artifactId >mybatisplus-plus</ artifactId > < version >1.5.1-RELEASE</ version > </ dependency > < dependency > < groupId >com.baomidou</ groupId > < artifactId >mybatis-plus-boot-starter</ artifactId > < version >3.1.0</ version > </ dependency > < dependency > < groupId >com.baomidou</ groupId > < artifactId >mybatis-plus-generator</ artifactId > < version >3.1.0</ version > </ dependency > |
2.实体类
1
2
3
4
5
6
7
8
9
10
11
|
@TableName ( "etl_job" ) public class Job implements Serializable { private static final long serialVersionUID=1L; @MppMultiId // 复合主键 private String etlSystem; @MppMultiId // 复合主键 private String etlJob; } |
3.Mapper类和mapper.xml
1
2
3
|
public interface JobMapper extends MppBaseMapper<Job> { } |
1
2
3
4
|
< resultMap id = "BaseResultMap" type = "com.dd.study.beans.Job" > < id column = "etl_system" property = "etlSystem" /> < id column = "etl_job" property = "etlJob" /> </ resultMap > |
4.Server和ServiceImpl
1
2
|
public interface JobService extends IMppService<Job> { } |
1
2
3
|
@Service public class JobServiceImpl extends MppServiceImpl<JobMapper, Job> implements JobService { } |
5.接下来就是正式应用复合主键相关的操作了
1
|
jobService.saveOrUpdateByMultiId(job); |
6.想要启动复合主键,还要记得在启动类加上@EnableMPP。
到此这篇关于mybatis-plus复合主键的使用的文章就介绍到这了,更多相关mybatis-plus复合主键内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/ypf2019/article/details/121286701