Commit fe5474b3 by 段启岩

话题检索添加分页

parent 6e523a14
......@@ -19,7 +19,6 @@ import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* @author 胡明森
......@@ -66,11 +65,14 @@ public class TopicApi {
@ApiOperation("检索话题")
@GetMapping("/topic/search")
public Response<List<Topic>> searchTopics(@RequestParam("keywords") String keywords) {
List<Topic> topics = topicService.searchTopics(keywords);
public Response<?> searchTopics(@Valid PageForm pageForm, BindingResult bindingResult,
@RequestParam("keywords") String keywords) {
if (bindingResult.hasErrors()) {
return Response.fieldError(bindingResult.getFieldError());
}
return Response.success(topics);
IPage<Topic> topicPage = topicService.searchTopics(keywords, pageForm.getPage(), pageForm.getSize());
return Response.success(new PageVO<>(topicPage));
}
......
......@@ -6,8 +6,6 @@ import cn.meteor.beyondclouds.modules.user.entity.User;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* <p>
* 话题表 服务类
......@@ -28,8 +26,10 @@ public interface ITopicService extends IService<Topic> {
/**
* 检索话题
* @param keywords
* @param pageNumber
* @param pageSize
*/
List<Topic> searchTopics(String keywords);
IPage<Topic> searchTopics(String keywords, Integer pageNumber, Integer pageSize);
/**
* 关注话题
......
......@@ -55,9 +55,11 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
}
@Override
public List<Topic> searchTopics(String keywords) {
return topicMapper.searchTopics(keywords);
public IPage<Topic> searchTopics(String keywords, Integer pageNumber, Integer pageSize) {
IPage<Topic> page = new Page<>(pageNumber, pageSize);
QueryWrapper<Topic> topicQueryWrapper = new QueryWrapper<>();
topicQueryWrapper.like("topic_name", keywords);
return page(page, topicQueryWrapper);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment