Mybatisplus-plus 1.3.1 发布,新增服务层根据复合主键 CRUD 操作

栏目: 软件资讯 · 发布时间: 5年前

内容简介:Mybatisplus-plus 1.3.1新增在service层操作复合主键进行增删改查相关操作的功能。 **从中央库引入jar** ```` <dependency> <groupId>com.github.jeffreyning</groupId> <artifactId>m...

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
````
@Mapper
public interface Test07Mapper extends MppBaseMapper<Test07Entity> {
}
````
````
service层继承IMppService
````
public interface Test07Service extends IMppService<Test07Entity> {
}
@Service
public 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);
    }
````

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Python编程无师自通

Python编程无师自通

[美] 科里·奥尔索夫(Cory Althoff) / 宋秉金 / 人民邮电出版社 / 2019-1-1 / 59

畅销Python编程类入门书,美国亚马逊Kindle编程类排行榜榜一。 作者从文科毕业,通过自学编程转行为专业程序员,在硅谷工作多年后成功技术创业。本书不仅教读者如何使用Python语言编程,还会介绍其他书中所忽略的、编程初学者应该了解并掌握的其他所有知识点。 本书作者是一名自学成才的程序员,经过一年的自学,掌握了编程技能并在eBay找到了一份软件工程师的工作。本书是作者结合个人经验写......一起来看看 《Python编程无师自通》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

SHA 加密
SHA 加密

SHA 加密工具