问题描述
定义一个类
private Integer id;//主键
private int projectClassDicId;//项目类型,来自于字典
private int stage;//阶段,不为空并且大于0 默认5,G1\G2\G3.…
private int logicRelation;//逻辑关系,定义并发顺序
Mapper
<select id="findBy" parameterType="com.npi.po.NpiProjectClass" resultMap="NpiProjectClass">
select
<include refid="SQL"/>
from npi_project_class
LEFT JOIN s_type on s_type.id=npi_project_class.project_class_dic_id
<where>
<if test="id!=null">
and npi_project_class.id=#{id}
</if>
<if test="stage!=null">
and npi_project_class.stage=#{stage}
</if>
<if test="projectClassDicId!=null">
and npi_project_class.project_class_dic_id=#{projectClassDicId}
</if>
<if test="isDeleted!=null">
and npi_project_class.is_deleted=#{isDeleted}
</if>
</where>
</select>
问题点:
当我调用的时候发现
stage、projectClassDicId 我就是没有给定义它的值(正常为NULL才对),但却自动默认输出0;因此里查询的时候总是失败。
原因:
int是一个包装类型,默认为0的;
byte 包装类是 Byte
short 包装类是 Short
int 包装类是 Integer
long 包装类是 Long
float 包装类是 Float
double 包装类是 Double
char 包装类是 Character
boolean 包装类是 Boolean
把相应类型设置为基本类型Integer会正常了。如下:
private Integer id;//主键
private Integer projectClassDicId;//项目类型,来自于字典
private Integer stage;//阶段,不为空并且大于0 默认5,G1\G2\G3.…
private Integer logicRelation;//逻辑关系,定义并发顺序