From c2a8312802c06313751cb1d90344144da1a39da9 Mon Sep 17 00:00:00 2001 From: isea533 Date: Tue, 18 Jul 2017 20:50:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96Example=E7=9A=84xml=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E8=A7=A3=E5=86=B3=E7=94=B1=E4=BA=8Eand,or?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4Example?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E7=A9=BA=E6=9D=A1=E4=BB=B6=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF=EF=BC=8C=E5=AE=8C=E5=96=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/mapperhelper/SqlHelper.java | 8 ++---- .../test/example/TestSelectByExample.java | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java b/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java index 717da268d..c6f5d304c 100644 --- a/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java +++ b/src/main/java/tk/mybatis/mapper/mapperhelper/SqlHelper.java @@ -612,10 +612,9 @@ public static String exampleCheck(Class entityClass) { public static String exampleWhereClause() { return "" + "\n" + - "\n" + " \n" + - " ${@tk.mybatis.mapper.util.OGNL@andOr(criteria)} " + " \n" + + " ${@tk.mybatis.mapper.util.OGNL@andOr(criteria)}" + " \n" + " \n" + " \n" + @@ -639,7 +638,6 @@ public static String exampleWhereClause() { " \n" + " \n" + " \n" + - "\n" + "" + ""; } @@ -651,10 +649,9 @@ public static String exampleWhereClause() { */ public static String updateByExampleWhereClause() { return "\n" + - "\n" + " \n" + - " ${@tk.mybatis.mapper.util.OGNL@andOr(criteria)} " + " \n" + + " ${@tk.mybatis.mapper.util.OGNL@andOr(criteria)}" + " \n" + " \n" + " \n" + @@ -678,7 +675,6 @@ public static String updateByExampleWhereClause() { " \n" + " \n" + " \n" + - "\n" + ""; } diff --git a/src/test/java/tk/mybatis/mapper/test/example/TestSelectByExample.java b/src/test/java/tk/mybatis/mapper/test/example/TestSelectByExample.java index 5b380339d..510aa1398 100644 --- a/src/test/java/tk/mybatis/mapper/test/example/TestSelectByExample.java +++ b/src/test/java/tk/mybatis/mapper/test/example/TestSelectByExample.java @@ -229,6 +229,31 @@ public void testExcludeColumnsByExample() { } } + @Test + public void testAndOr() { + SqlSession sqlSession = MybatisHelper.getSqlSession(); + try { + CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); + Example example = new Example(Country.class); + example.createCriteria().andGreaterThan("id", 100).andLessThan("id", 151); + example.or().andLessThan("id", 41); + List countries = mapper.selectByExample(example); + //查询总数 + Assert.assertEquals(90, countries.size()); + + //当不使用条件时,也不能出错 + example = new Example(Country.class); + example.createCriteria(); + example.or(); + example.and(); + countries = mapper.selectByExample(example); + //查询总数 + Assert.assertEquals(183, countries.size()); + } finally { + sqlSession.close(); + } + } + @Test public void testOrderBy() { SqlSession sqlSession = MybatisHelper.getSqlSession();