Java Code Examples for tk.mybatis.mapper.entity.Example#excludeProperties()

The following examples show how to use tk.mybatis.mapper.entity.Example#excludeProperties() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestSelectByExample.java    From Mapper with MIT License 6 votes vote down vote up
@Test
public void testExcludeColumnsByExample() {
    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);
        example.excludeProperties("id");
        List<Country> countries = mapper.selectByExample(example);
        //查询总数
        Assert.assertEquals(90, countries.size());
    } finally {
        sqlSession.close();
    }
}
 
Example 2
Source File: TestSelectByExample.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 指定排除的查询字段不存在或拼写错误
 */
@Test
public void testExcludePropertisCheckWrongSpell() {
    exception.expect(MapperException.class);
    exception.expectMessage("类 Country 不包含属性 'countrymame',或该属性被@Transient注释!");
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = new Example(Country.class);
        example.excludeProperties(new String[]{"countrymame"});
        example.createCriteria().andEqualTo("id", 35);
        List<Country> country = mapper.selectByExample(example);
    } finally {
        sqlSession.close();
    }
}
 
Example 3
Source File: TestSelectByExample.java    From Mapper with MIT License 6 votes vote down vote up
/**
 * 指定排除的查询字段为@Transient注释字段
 */
@Test
public void testExcludePropertisCheckTransient() {
    exception.expect(MapperException.class);
    exception.expectMessage("类 Country 不包含属性 'dynamicTableName123',或该属性被@Transient注释!");
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = new Example(Country.class);
        example.excludeProperties(new String[]{"dynamicTableName123"});
        example.createCriteria().andEqualTo("id", 35);
        List<Country> country = mapper.selectByExample(example);
    } finally {
        sqlSession.close();
    }
}