在@Mapper注解下来编写SQL语句

时间:2025-04-05 12:17:30
@Mapper @Repository public interface UserMapper { /**模糊查询**/ @Select("SELECT , , FROM User a WHERE LIKE CONCAT('%',#{0},'%') ") public List<User> selectByName(String username); /**将查询到的字段进行映射到对应的java对象内**/ @Select("select f.user_id user_id, f.type_id, f.friend_id, username, sign, phone, from im_friend f left join sys_user u on f.friend_id= where f.user_id= #{userId}") @Results(value = { @Result(column = "user_id", property = "userId"), @Result(column = "type_id", property = "typeId"), @Result(column = "friend_id", property = "friendId"), @Result(column = "username", property = "username"), @Result(column = "sign", property = "sign"), @Result(column = "phone", property = "phone"), @Result(column = "avatar", property = "avatar"), }) List<UserFriend> findUserFriend(String userId); /** * 根据用户ID修改头像 * @param userId 用户ID * @param imgUrl 修改的url */ @Update("update sys_user set avatar = #{imgUrl} where username = #{userId}") void changeHeadPicture(@Param("userId")String userId,@Param("imgUrl")String imgUrl); }