mybatis-plus复合主键
叶儿飞飞 人气:11.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>
2.实体类
@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
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>
4.Server和ServiceImpl
public interface JobService extends IMppService<Job> { }
@Service public class JobServiceImpl extends MppServiceImpl<JobMapper, Job> implements JobService { }
5.接下来就是正式应用复合主键相关的操作了
jobService.saveOrUpdateByMultiId(job);
6.想要启动复合主键,还要记得在启动类加上@EnableMPP。
加载全部内容