欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-04-14 15:56:48
...
实体查询的默认值处理问题:

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

1,条件有多少转义多少
Example example = new Example(TbPowerGroup.class);
example.createCriteria().andLike("flag", "%"+cusTradeKind+"%");
example.setOrderByClause("levelCode asc");
List<TbPowerGroup> 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查询
相关标签: 查询