转自:https://blog.youkuaiyun.com/u011662320/article/details/80612425
mybatis异常:
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'companyId' in 'class java.lang.Long'
mapper接口:
List<BranchInfo> findListStatus1(Long companyId );
mybatis的mapper文件:
- <select id="findListStatus1" parameterType="java.lang.Long" resultType="com.xm.admin.dao.model.BranchInfo">
- SELECT * FROM branch_info
- WHERE status = 1
- <if test="companyId != null">
- and company_id = #{companyId,jdbcType=BIGINT}
- </if>
- </select>
报错是mybatis中if test的判空时报错了。
解决方案1:
mapper接口改为:
List<BranchInfo> findListStatus1(@Param(value="companyId")Long companyId );
引入的jar包:
import org.apache.ibatis.annotations.Param;
解决方案二:
修改mapper文件:
- <select id="findListStatus1" parameterType="java.lang.Long" resultType="com.xm.admin.dao.model.BranchInfo">
- SELECT * FROM branch_info
- WHERE status = 1
- <if test="_parameter != null">
- and company_id = #{companyId,jdbcType=BIGINT}
- </if>
- </select>