在SpringBoot中自定义sql语句
2017-12-25 19:49
501 查看
关于在SpringBoot中自定义Sql语句
上面代码中selectConversationList()就是自定义的Sql,只需要在方法的上面加上注解@Select即可,当然还有其他的例如Delete,Update。参数怎样定义在上面也有写到
@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。参数怎样定义在上面也有写到
相关文章推荐
- springboot+mybatis显示sql语句
- 记一次大坑:SpringBoot+Mybatis项目中,配置文件中的修改了SQL语句后不生效
- springboot 使用mybaties打印sql语句
- Spring Boot Jpa之构建动态SQL查询语句
- 使用spring-boot-starter-data-jpa 怎么配置使运行时输出SQL语句
- springboot mybatis 整合后输出sql语句
- Spring data jpa 自定义SQL语句遇到错误Not supported for DML operations
- spring boot2.0 连接mysql ,自定义JpaRepository 分页, 封装jpa底层sql(二)
- Spring boot data JPA 自定义JPQL语句,以及PagingAndSortingRepository接口实现分页查询
- spring data jpa 自定义复杂sql语句(多个select嵌套) 并返回自定义对象
- SpringBoot + Mybatis 在控制台输出sql语句
- Spring Boot应用连接数据库MySQL,并编写自定义SQL
- idea+Springboot在控制台打印sql语句
- springboot+druid sql监控没有显示sql语句
- springboot2.0+log4jdbc将sql语句完整写入日志文件并分开 4000 保存
- 使用spring-boot-starter-data-jpa 怎么配置使运行时输出SQL语句
- 使用spring-boot-starter-data-jpa 怎么配置使运行时输出SQL语句
- SpringBoot如何导入自定义配置的yml文件
- Spring Boot自定义Banner
- Spring 集成mybatis 3.几之后,打印sql语句到控制台