实体查询的默认值处理问题

阅读更多
实体查询的默认值处理问题:

由于实体类型有不同的默认值,直接用原生的实体查询(除通用mapper外(去除任何默认值))都会把默认值当作查询条件(用String对象类型默认null没有影响,
int 默认0有影响)

1,条件有多少转义多少
Example example = new Example(TbPowerGroup.class);
example.createCriteria().andLike("flag", "%"+cusTradeKind+"%");
example.setOrderByClause("levelCode asc");
List list= tbPowerGroupMapper.selectByExample(example);


2,通用mapper自动去了默认null,都是string,没有int等所以默认也就去了
OpmUser opmUserNew = new OpmUser();
opmUserNew.setCode(code);
user = opmUserMapper.selectOne(opmUserNew);

==>  Preparing: SELECT ID,CODE,PASSWORD,NAME,TELEPHONE,EMAIL,ORGANID,VALID,MEMO,LEVEL1,LAST_LOGIN_DATE AS lastLoginDate,LAST_LOGIN_TIME AS lastLoginTime,ONLINE_MARK AS onlineMark,ONLINE_IP AS onlineIp,SESSIONID FROM OPM_USER WHERE CODE = ?
==> Parameters: system(String)==>  Preparing: SELECT ID,CODE,PASSWORD,NAME,TELEPHONE,EMAIL,ORGANID,VALID,MEMO,LEVEL1,LAST_LOGIN_DATE AS lastLoginDate,LAST_LOGIN_TIME AS lastLoginTime,ONLINE_MARK AS onlineMark,ONLINE_IP AS onlineIp,SESSIONID FROM OPM_USER WHERE CODE = ?
==> Parameters: system(String)



SESSIONID  改为int  默认的0就作为条件了(实体查询只会省略null的)

==>  Preparing: SELECT ID,CODE,PASSWORD,NAME,TELEPHONE,EMAIL,ORGANID,VALID,MEMO,LEVEL1,LAST_LOGIN_DATE AS lastLoginDate,LAST_LOGIN_TIME AS lastLoginTime,ONLINE_MARK AS onlineMark,ONLINE_IP AS onlineIp,SESSIONID FROM OPM_USER WHERE SESSIONID = ?
==> Parameters: 0(Integer)



3,直接用JdbcTemplate的sql查询

你可能感兴趣的:(查询)