mybatis传入array

1.mapper.java中

List<MacTicket> selectByPrimaryKeyList(String[] stringArray);

mapper.xml中

<select id="selectByPrimaryKeyList" parameterType="int" resultMap="BaseResultMap">

<foreach collection="array" item="id" index="index" open="(" close=")" separator=",">

#{id,jdbcType=VARCHAR}

</foreach>

亲测,重点说下parameterType实际不写也可以,或者写其他的都行,但是collection="array"这个必须写,mapper.java中的String[]也必须写

2.mapper.xml中if判断

<sql> sql片段中表的别名例如ticket和sql语句中尽量统一,引用此sql片段的语句的别名遵循sql片段的表别名

<if test="statusCd!=null and statusCd!=''"></if> if判断时null和空串都要判断

<if test="name !=null and name!=''">and ticket.name like concat ('name',#{name},'%')</if>  模糊查询

<if test="createTimeStart=null and createTimeStart!=''">and ticket.create_time &gt;#{createTimeStart}</if> 大于等于

<if test="createTimeEnd=null and createTimeEnd!=''">and ticket.create_time &lt;#{createTimeEnd}</if> 小于等于

</sql>

猜你喜欢

转载自blog.csdn.net/qq_34412985/article/details/80753009