SpringBoot 项目:Mapper 查询条件字段默认0的解决办法

问题描述

定义一个类

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;//逻辑关系,定义并发顺序

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值