小编给大家分享一下mybatis-plus复合主键怎么用,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
mybatis-plus 版本
<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>
实体类
@TableName("etl_job")public class Job implements Serializable { private static final long serialVersionUID=1L; @MppMultiId // 复合主键 private String etlSystem; @MppMultiId // 复合主键 private String etlJob;}
Mapper类和mapper.xml
public interface JobMapper extends MppBaseMapper<Job> {}
<resultMap id="BaseResultMap" type="com.dd.study.beans.Job"> <id column="etl_system" property="etlSystem" /> <id column="etl_job" property="etlJob" /> </resultMap>
Server和ServiceImpl
public interface JobService extends IMppService<Job> { }
@Servicepublic class JobServiceImpl extends MppServiceImpl<JobMapper, Job> implements JobService {}
接下来就是正式应用复合主键相关的操作了
jobService.saveOrUpdateByMultiId(job);
想要启动复合主键,还要记得在启动类加上@EnableMPP。
看完了这篇文章,相信你对“mybatis-plus复合主键怎么用”有了一定的了解,如果想了解更多相关知识,欢迎关注编程网行业资讯频道,感谢各位的阅读!