@Param注解的用法解析

来源:互联网 发布:java编程经验技巧 编辑:程序博客网 时间:2024/05/29 15:30

实例一 @Param注解单一属性
dao层示例
Public User selectUser(@param(“userName”) String name,@param(“userpassword”) String password);
xml映射对应示例

<select id=" selectUser" resultMap="BaseResultMap">     select  *  from user_user_t   where user_name = #{userName,jdbcType=VARCHAR} and user_password=#{userPassword,jdbcType=VARCHAR}  </select>

意:采用#{}的方式把@Param注解括号内的参数进行引用(括号内参数对应的是形参如 userName对应的是name);
dao层示例
public List getUserInformation(@Param(“user”) User user);
xml映射对应示例

<select id="getUserInformation" parameterType="com.github.demo.vo.User" resultMap="userMapper">          select           <include refid="User_Base_Column_List" />          from mo_user t where 1=1                        <!-- 因为传进来的是对象所以这样写是取不到值得 -->              <if test="user.userName!=null  and user.userName!=''">   and   t.user_name = #{user.userName}  </if>              <if test="user.userAge!=null  and user.userAge!=''">   and   t.user_age = #{user.userAge}  </if>      </select>  
0 0