dao层:
@Mapper
public interface UserPunchCardMapper extends BaseMapper<UserPunchCard> {
List<UserPunchCard> selectByUserCode(@Param("userCode") String userCode);
}
对应的xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mes.production.dao.UserPunchCardMapper">
<select id="selectByUserCode" resultType="com.mes.production.entity.UserPunchCard">
SELECT * FROM PR_T_USER_PUNCH_CARD WHERE USER_CODE = #{userCode}
</select>
报错原因: 传入了为null的userCode
解决方法: 根据业务如果允许参数为空时返回全部值,那么可以在xml里添加非空判断,如下:
<select id="selectByUserCode" resultType="com.mes.production.entity.UserPunchCard">
SELECT * FROM PR_T_USER_PUNCH_CARD WHERE 1 = 1
<if test="userCode != null and userCode != ''">
AND USER_CODE = #{userCode}
</if>
</select>
如果业务不允许,那么在业务层代码里添加非空判断, 不为空才调用该方法即可