Springboot mybitas dao层使用的注解

@Mapper

使用@Mapper注解要定义成一个接口interface

作用:1.使用@Mapper将NewsDAO接口交给Spring进行管理

2.不用写Mapper映射文件(XML)

3.为这个NewsDAO接口生成一个实现类,让别的类进行引用

@param

当有多个参数的时候使用@param注解.

在mapper.xml中使用的时候,#{对象别名.属性名},如#{user.userName}

注意,使用了@pram注解的话在mapper.xml不加parameterType。

public List<UserExtension> selectUser( @Param("user") UserExtension user);
<select id=" selectUser" resultMap="BaseResultMap">
   select  *  from user_user_t   where user_name = #{user.userName,jdbcType=VARCHAR} and user_area=#{user.userArea,jdbcType=VARCHAR}
</select> 

select 里面的#{user.userName}的user是@Param("user")里的user, 与UserExtension user 无关。UserExtension user 的参数可以是任何有效的变量。如:UserExtension userExtension。只要@Param("user")里的参数不变,就不会影响都select里的。

详细请参见:https://my.oschina.net/u/2367628/blog/757653

@Insert等

    @Insert({"insert into ", TABLE_NAME, "(", INSET_FIELDS,
            ") values (#{name},#{password},#{salt},#{headUrl})"})
    int addUser(User user); //Insert返回值类型是int

    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where id=#{id}"})
    User selectById(int id);

    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where name=#{name}"})
    User selectByName(String name);

    @Update({"update ", TABLE_NAME, " set password=#{password} where id=#{id}"})
    void updatePassword(User user);

    @Delete({"delete from ", TABLE_NAME, " where id=#{id}"})
    void deleteById(int id);
 

猜你喜欢

转载自blog.csdn.net/qq_38444415/article/details/90182175