mybatis使用in查询以及报java.lang.NullPointerException: target is null for method size异常解决办法

mybatis使用in查询以及报java.lang.NullPointerException: target is null for method size异常解决办法

一、解决办法

<if test="param.projectIdList !=null and param.projectIdList.size()>0">
    	and project_id in
    <foreach collection="list" item="projectId" index="index" open="(" close=")" separator=",">
     	#{projectId}
    </foreach>
</if>

在外层条件判断处,不等于空并且size大小大于0这两个条件都需具备

二、如何使用

1、建立通用查询结果列

<!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
         id,settlement_id,project_id,project_type_id,project_no,batno,active_code,name,telephone,sex,id_number,account_no,account_name,bank_name,bank_province,bank_city,account_phone,issue_amount,issue_time,invoice_amount,audit_status,transfer_status,err_msg,receipt_url,invoice_url,tax_personal,tax_value_add,staff_code,work_in,position,actived_time,contract_no,contract_file,contract_sign,contract_sign_status,create_time,update_time,deleted,calculation_method,service_amount
    </sql>

以下字段填写你所需查询的字段

id,settlement_id,project_id,project_type_id,project_no,batno,active_code,name,telephone,sex,id_number,account_no,account_name,bank_name,bank_province,bank_city,account_phone,issue_amount,issue_time,invoice_amount,audit_status,transfer_status,err_msg,receipt_url,invoice_url,tax_personal,tax_value_add,staff_code,work_in,position,actived_time,contract_no,contract_file,contract_sign,contract_sign_status,create_time,update_time,deleted,calculation_method,service_amount

2、编写查询语句

<select id="getProjectStaffPageList" resultType="io.tensoon.springbootplus.business.vo.ProjectStaffQueryVo">
        select
        <include refid="Base_Column_List"/>
        from 
        	project_staff 
        where
        	transfer_status=1 and audit_status=1
        	<if test="param.projectId!=null">
            	and project_id = #{param.projectId}
        	</if>
</select>

3、使用in查询

<if test="param.projectIdList !=null and param.projectIdList.size()>0">
            and project_id in
            <foreach collection="list" item="projectId" index="index" open="(" close=")" separator=",">
                #{projectId}
            </foreach>
</if>
<select id="getProjectStaffPageList" resultType="io.tensoon.springbootplus.business.vo.ProjectStaffQueryVo">
        select
        <include refid="Base_Column_List"/>
        from 
        	project_staff 
        where
        	transfer_status=1 and audit_status=1
        	<if test="param.projectId!=null">
            	and project_id = #{param.projectId}
        	</if>
        	<if test="param.projectIdList !=null and param.projectIdList.size()>0">
            	and project_id in
           		<foreach collection="list" item="projectId" index="index" open="(" close=")" separator=",">
                	#{projectId}
           		</foreach>
			</if>
</select>

collection: 传入参数的类型 数组用array 列表使用list
item: 传入参数的赋值对象 一般为#{projectId}此处projectId值
index: 起始位置
open="(" : 以 ‘(’ 开始
close=")": 以 ‘)’ 结束
separator=",": 以 ‘,’ 分隔开
每赋一个值都填充进 ‘(’ 和 ‘)’ 中间并以 ‘,’ 分隔开
最后拼接结果为: ‘(第一个值,第二个值,…)’

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值