|
@@ -3,13 +3,15 @@
|
|
|
* @create 2022-09-15 14:48
|
|
|
*/
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import com.gyee.backconfig.BackConfigMain;
|
|
|
import com.gyee.backconfig.mapper.auto.XrpProjectplanMapper;
|
|
|
import com.gyee.backconfig.model.auto.XrpProjectplan;
|
|
|
+import com.gyee.backconfig.service.auto.IXrpProjectplanService;
|
|
|
import com.gyee.common.model.StringUtils;
|
|
|
-import net.minidev.json.writer.UpdaterMapper;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -33,6 +35,14 @@ public class MyBatisPlusWrapperTest {
|
|
|
@Autowired
|
|
|
private XrpProjectplanMapper xrpProjectplanMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IXrpProjectplanService xrpProjectplanService;
|
|
|
+ @Test
|
|
|
+ public void testRemove(){
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<XrpProjectplan>();
|
|
|
+ queryWrapper.eq("id","ea87011f98c11dae924c73802ce1b4d8");
|
|
|
+ xrpProjectplanService.remove(queryWrapper);
|
|
|
+ }
|
|
|
@Test
|
|
|
public void testWrapper(){
|
|
|
//==> Preparing: SELECT ID,PROJECTID,GENERATINGCAPACITY,OUTAGEHOURS,YEAR,MONTH,WINDPOWER,isdeleted FROM XRP_PROJECTPLAN WHERE isdeleted=1
|
|
@@ -61,11 +71,12 @@ public class MyBatisPlusWrapperTest {
|
|
|
//删除id
|
|
|
QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
|
//queryWrapper.isNotNull("month");
|
|
|
- queryWrapper.eq("month","");
|
|
|
+ queryWrapper.eq("GENERATINGCAPACITY","100.4");
|
|
|
int delete = xrpProjectplanMapper.delete(queryWrapper);
|
|
|
System.out.println("result"+ delete);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
//update biao set zd="" where month='' and id or year
|
|
|
@Test
|
|
|
public void testUpdate2(){
|
|
@@ -92,7 +103,7 @@ public class MyBatisPlusWrapperTest {
|
|
|
//lambda中的条件优先执行
|
|
|
//==> Preparing: UPDATE XRP_PROJECTPLAN SET PROJECTID=?, GENERATINGCAPACITY=?
|
|
|
// WHERE isdeleted=1 AND (month = ? AND (id > ? OR year LIKE ?))
|
|
|
- QueryWrapper<XrpProjectplan> queryWrapper = new QueryWrapper<>();
|
|
|
+ UpdateWrapper<XrpProjectplan> queryWrapper = new UpdateWrapper<>();
|
|
|
queryWrapper.eq("month","")
|
|
|
.and(
|
|
|
i->i.gt("id",1570251305913802753L)
|
|
@@ -109,13 +120,21 @@ public class MyBatisPlusWrapperTest {
|
|
|
System.out.println("result:"+result);
|
|
|
}
|
|
|
|
|
|
+ //函数式接口指定
|
|
|
@Test
|
|
|
- public void testPro(){
|
|
|
- QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
|
- queryWrapper.select("ID","PROJECTID","YEAR");
|
|
|
- //组装属性字段
|
|
|
- List<Map<String, Object>> maps = xrpProjectplanMapper.selectMaps(queryWrapper);
|
|
|
- maps.forEach(System.out::println);
|
|
|
+ public void testUpdatePerLambda(){
|
|
|
+ LambdaUpdateWrapper<XrpProjectplan> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.like(XrpProjectplan::getYear,"")
|
|
|
+ .gt(XrpProjectplan::getMonth,"5")
|
|
|
+ .and(
|
|
|
+ i->i.gt(XrpProjectplan::getId,1570251306048020482L)
|
|
|
+ .or()
|
|
|
+ .like(XrpProjectplan::getYear,"49")
|
|
|
+ );
|
|
|
+ updateWrapper
|
|
|
+ .set(XrpProjectplan::getProjectid,"120").set(XrpProjectplan::getGeneratingcapacity,111.7);
|
|
|
+ int result = xrpProjectplanMapper.update(null, updateWrapper);
|
|
|
+ System.out.println("result:"+result);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -130,10 +149,24 @@ public class MyBatisPlusWrapperTest {
|
|
|
System.out.println("result:"+result);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testPro(){
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
|
+ queryWrapper.select("ID","PROJECTID","YEAR","generatingcapacity");
|
|
|
+ //组装属性字段
|
|
|
+ List<Map<String, Object>> maps = xrpProjectplanMapper.selectMaps(queryWrapper);
|
|
|
+ maps.forEach(System.out::println);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//组装条件
|
|
|
@Test
|
|
|
public void test(){
|
|
|
- String year="";
|
|
|
+ String year="5";
|
|
|
Long idBegin=1570251304856838145L;
|
|
|
Long idEnd=1570284357834518534L;
|
|
|
QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
@@ -143,6 +176,45 @@ public class MyBatisPlusWrapperTest {
|
|
|
}
|
|
|
|
|
|
//if(idBegin)
|
|
|
+ if (idBegin == null) {
|
|
|
+ queryWrapper.ge("id",idBegin);
|
|
|
+ }
|
|
|
+ if (idEnd == null) {
|
|
|
+ queryWrapper.le("id",idEnd);
|
|
|
+ }
|
|
|
|
|
|
+ List<XrpProjectplan> list = xrpProjectplanMapper.selectList(queryWrapper);
|
|
|
+ list.forEach(System.out::println);
|
|
|
}
|
|
|
+
|
|
|
+ //组装条件 Condition
|
|
|
+ @Test
|
|
|
+ public void testCondition(){
|
|
|
+ String year="5";
|
|
|
+ Long idBegin=1570251304856838145L;
|
|
|
+ Long idEnd=1570284357834518534L;
|
|
|
+ QueryWrapper<XrpProjectplan> queryWrapper=new QueryWrapper<>();
|
|
|
+ queryWrapper.like(StringUtils.isNotEmpty(year),"year",year)
|
|
|
+ .ge(idBegin!=null,"id",idBegin)
|
|
|
+ .le(idEnd!=null,"id",idEnd);
|
|
|
+ List<XrpProjectplan> xrpProjectplanList = xrpProjectplanMapper.selectList(queryWrapper);
|
|
|
+ xrpProjectplanList.forEach(System.out::println);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void TestLambda(){
|
|
|
+ String year="5";
|
|
|
+ Long idBegin=1570251304856838145L;
|
|
|
+ Long idEnd=1570284357834518534L;
|
|
|
+ LambdaQueryWrapper<XrpProjectplan> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.like(StringUtils.isNotBlank(year),XrpProjectplan::getYear,year)
|
|
|
+ .ge(idBegin!=null,XrpProjectplan::getId,idBegin)
|
|
|
+ .le(idEnd!=null,XrpProjectplan::getId,idEnd);
|
|
|
+ List<XrpProjectplan> list = xrpProjectplanMapper.selectList(lambdaQueryWrapper);
|
|
|
+ list.forEach(System.out::println);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|