内容:直接查找数据库返回文章的列表即可。
PraiseController.java
//获取文章列表
@GetMapping("list")
public BaseResponse articleList(){
BaseResponse response=new BaseResponse(StatusCode.Success);
try {
response.setData(praiseService.getAll());
}catch (Exception e){
response=new BaseResponse(StatusCode.Fail.getCode(),e.getMessage());
}
return response;
}
PraiseService.java
//获取文章的列表
public List<Article> getAll() throws Exception{
return articleMapper.selectAll();
}
ArticleMapper.xml
<select id="selectAll" resultType="com.redis.model.entity.Article">
select
a.*, b.name as userName
from
article as a
left join user as b on b.id = a.user_id
where a.is_active = 1
order by a.create_time desc
</select>