From e2e99d3faa31d28c8c6e144cac3696adb1df4557 Mon Sep 17 00:00:00 2001 From: ninghao Date: Sun, 3 Jan 2021 21:13:09 +0800 Subject: [PATCH] =?UTF-8?q?service=E5=B1=82=E5=A4=9A=E4=B8=BB=E9=94=AE?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 32 ++++++++++++++++++- pom.xml | 2 +- .../mybatisplus/service/IMppService.java | 24 ++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/github/jeffreyning/mybatisplus/service/IMppService.java diff --git a/README.md b/README.md index 01e473b..23b55ab 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ mybatisplus-plus对mybatisplus的一些功能补充 **根据多个字段联合主键增删改查** 原生mybatisplus只支持一个主键,mpp支持多个字段联合主键增删改查,mapper需要继承MppBaseMapper
实体类中联合主键的字段需要用@MppMultiId注解修饰
+如果需要在service使用多主键相关操作,可以直接继承IMppService接口
**优化分页插件实现在不分页时进行排序操作** 原生mybatisplus分页与排序是绑定的,mpp优化了分页插件,使用MppPaginationInterceptor插件
@@ -47,7 +48,7 @@ mpp的lambda方式
com.github.jeffreyning mybatisplus-plus - 1.3.0-RELEASE + 1.3.1-RELEASE ```` @@ -208,6 +209,35 @@ public interface Test07Mapper extends MppBaseMapper { test07Mapper.updateByMultiId(retEntity); } ```` +service层继承IMppService +```` +public interface Test07Service extends IMppService { +} +@Service +public class Test07ServiceImpl extends ServiceImpl 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); + } +```` + **优化分页插件实现在不分页时进行排序操作** 使用MppPaginationInterceptor插件 ```` diff --git a/pom.xml b/pom.xml index 3c595b0..6fc81f8 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.github.jeffreyning mybatisplus-plus - 1.3.0-RELEASE + 1.3.1-RELEASE com.baomidou diff --git a/src/main/java/com/github/jeffreyning/mybatisplus/service/IMppService.java b/src/main/java/com/github/jeffreyning/mybatisplus/service/IMppService.java new file mode 100644 index 0000000..249e7a3 --- /dev/null +++ b/src/main/java/com/github/jeffreyning/mybatisplus/service/IMppService.java @@ -0,0 +1,24 @@ +package com.github.jeffreyning.mybatisplus.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; +import com.github.jeffreyning.mybatisplus.base.MppBaseMapper; + +/** + * @author ninghao + */ +public interface IMppService extends IService { + MppBaseMapper getBaseMapper(); + default boolean updateByMultiId(T entity) { + return SqlHelper.retBool(this.getBaseMapper().updateByMultiId(entity)); + } + + default boolean deleteByMultiId(T entity) { + return SqlHelper.retBool(this.getBaseMapper().deleteByMultiId(entity)); + } + + default T selectByMultiId(T entity) { + return this.getBaseMapper().selectByMultiId(entity); + } + +}