关于在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。参数怎样定义在上面也有写到