Native mybatisplus only supports one primary key, mpp supports multiple fields to add, delete, and modify the primary key. Mapper needs to inherit the fields of the combined primary key in the MppBaseMapper entity class, which needs to be modified with @MppMultiId
Use @MppMultiId on instance class member variables to indicate the combined primary key
@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
@Mapper
public interface Test07Mapper extends MppBaseMapper<Test07Entity> {
}
根据多主键增删改查
public void testMultiId(){
//id
Test07Entity idEntity=new Test07Entity();
idEntity.setK1(1);
idEntity.setK2("111");
//del
test07Mapper.deleteByMultiId(idEntity);
//add
test07Mapper.insert(idEntity);
//query
Test07Entity retEntity=test07Mapper.selectByMultiId(idEntity);
retEntity.setCol1("xxxx");
//update
test07Mapper.updateByMultiId(retEntity);
}