Mybatisplus-plus 1.3.1新增在service層操作複合主鍵進行增刪改查相關操作的功能。
**從中央庫引入jar**```` <dependency> <groupId>com.github.jeffreyning</groupId> <artifactId>mybatisplus-plus</artifactId> <version>1.3.1-RELEASE</version> </dependency>````
在實例類成員變量上使用@MppMultiId表明聯合主鍵````@TableName("test07")public class Test07Entity { @MppMultiId @TableField(value = "k1") private Integer k1; @MppMultiId @TableField(value = "k2") private String k2; @TableField(value = "col1") private String col1; @TableField(value = "col2") private String col2; ````mapper需要繼承MppBaseMapper````@Mapperpublic interface Test07Mapper extends MppBaseMapper<Test07Entity> {}````
````service層繼承IMppService````public interface Test07Service extends IMppService<Test07Entity> {}@Servicepublic class Test07ServiceImpl extends ServiceImpl<Test07Mapper, Test07Entity> implements Test07Service {}````在service層調用多主鍵操作```` public void testMultiIdService(){ //id Test07Entity idEntity=new Test07Entity(); idEntity.setK1(1); idEntity.setK2("111"); //del test07Service.deleteByMultiId(idEntity); //add test07Service.save(idEntity); //query Test07Entity retEntity=test07Service.selectByMultiId(idEntity); retEntity.setCol1("xxxx"); //update test07Mapper.updateByMultiId(retEntity); }````