您的位置:首页 > 编程语言 > Java开发

在SpringBoot中自定义sql语句

2017-12-25 19:49 501 查看
关于在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。参数怎样定义在上面也有写到
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: