Mybatis里常用的注解使用

Mybatis里常用的注解使用

一、@Param示例

说明:可以看到使用了@Param注解以后,map.xml里面就没有使用parameterType了

实例一 @Param注解单一属性

dao层示例

Public User selectUser(@param(“userName”) String name,@param(“userpassword”) String password);

xml映射对应示例 (说明:可以看到使用了@Param注解以后,map.xml里面就没有使用parameterType了)

 <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);

实例二 @Param注解JavaBean对象

dao层

public List<student> selectuser(@Param(value = "page")int pn ,@Param(value = "st")student student);

xml映射 (说明:可以看到使用了@Param注解以后,map.xml里面就没有使用parameterType了)

<select id="selectuser" resultType="com.user.entity.student">
    SELECT * FROM student
    where sname like concat(concat("%",#{st.sname}),"%")
    LIMIT #{page} ,5
</select>
posted @ 2019-09-18 12:41  抬头不见星空  阅读(62)  评论(0)    收藏  举报