实体查询的默认值处理问题
程序员文章站
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查询
由于实体类型有不同的默认值,直接用原生的实体查询(除通用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查询
上一篇: 领域模型设计
下一篇: 两款php 截取字符串函数_PHP教程
推荐阅读
-
查询mysql里面的datetime字段,结果赋给实体类中是Timestamp类型的属性
-
mybatis-plus的selectById(或者selectOne)在根据主键ID查询实体对象的时候偶尔会出现null的问题记录
-
MyBatis Plus 将查询结果封装到指定实体的方法步骤
-
Spring Data JPA实现查询结果返回map或自定义的实体类
-
关于查询返回实体的有关问题
-
关于查询返回实体的有关问题
-
spring data jpa 关联join查询出自定义实体java bean的坑
-
MyBatis生成的实体条件,并在页面根据一些字段进行模糊查询
-
Java中使用hql,sql查询返回的list
-
Java中使用hql,sql查询返回的list