1. 程式人生 > >在SpringBoot中自定義sql語句

在SpringBoot中自定義sql語句

關於在SpringBoot中自定義Sql語句

@Mapper
public interface MessageMapper {
    int countByExample(MessageExample example);

    int deleteByExample(MessageExample example);

    int deleteByPrimaryKey(String id);

    int insert(Message record);

    int insertSelective(Message record);

    List<Message> selectByExample(MessageExample example);

    Message selectByPrimaryKey(String id);

    int
updateByExampleSelective(@Param("record") Message record, @Param("example") MessageExample example); int updateByExample(@Param("record") Message record, @Param("example") MessageExample example); int updateByPrimaryKeySelective(Message record); int updateByPrimaryKey(Message record); @Select
("select *,count(*) as count from message WHERE toid = #{userId} GROUP BY formid ORDER BY created_date desc limit #{offset}, #{limit}") List<Message> selectConversationList(@Param("userId") String userId, @Param("offset") int offset, @Param("limit") int limit); @Update("update message set has_read = 1 where conversation_id = #{conversationId}"
) void updateMessageHasReadByConversationId(@Param("conversationId") String conversationId); } }

上面程式碼中selectConversationList()就是自定義的Sql,只需要在方法的上面加上註解@Select即可,當然還有其他的例如Delete,Update。引數怎樣定義在上面也有寫到