@param

来源:互联网 发布:51单片机流水灯原理图 编辑:程序博客网 时间:2024/05/16 17:27

项目报红:

Causedby: org.apache.ibatis.reflection.ReflectionException: There is no getter forproperty named 'phone' in 'class java.lang.String'

经检查发现原来是在对应的mapper接口中参数未添加@param,因此顺手整理下@param

@Param注解为参数命名

语法:@Param("参数名称")

eg:

AccountPO selectAccountByUserName(@Param("UserName") String UserName,@Param("phone") String phone);

对应xml中分为两种情况

一:导入的包为:org.apache.ibatis.annotations.Param;

       对应的xml为:

<select id="selectAccountByUserName" parameterType="java.lang.String" resultMap="BaseResultMap">    select    <include refid="Base_Column_List"/>    from acct_account    where    UserName = #{UserName,jdbcType=VARCHAR}    and    phone=#{phone,jdbcType=VARCHAR} </select>
二、导入的包为 :org.springframework.data.repository.query.Param

        对应xml为:

<select id="selectAccountByUserName" parameterType="java.lang.String" resultMap="BaseResultMap">    select    <include refid="Base_Column_List"/>    from acct_account    where    UserName = #{0,jdbcType=VARCHAR}    and    phone=#{1,jdbcType=VARCHAR}</select>

注:mybatis中@param在xml中是根据参数名称取值,与接口中参数名称一一对应

        spring中@param在xml中是按照参数顺序取值,从0开始

     



原创粉丝点击