Commit fe5474b3 by 段启岩

话题检索添加分页

parent 6e523a14
...@@ -19,7 +19,6 @@ import org.springframework.validation.BindingResult; ...@@ -19,7 +19,6 @@ import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List;
/** /**
* @author 胡明森 * @author 胡明森
...@@ -66,11 +65,14 @@ public class TopicApi { ...@@ -66,11 +65,14 @@ public class TopicApi {
@ApiOperation("检索话题") @ApiOperation("检索话题")
@GetMapping("/topic/search") @GetMapping("/topic/search")
public Response<List<Topic>> searchTopics(@RequestParam("keywords") String keywords) { public Response<?> searchTopics(@Valid PageForm pageForm, BindingResult bindingResult,
@RequestParam("keywords") String keywords) {
List<Topic> topics = topicService.searchTopics(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; ...@@ -6,8 +6,6 @@ import cn.meteor.beyondclouds.modules.user.entity.User;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/** /**
* <p> * <p>
* 话题表 服务类 * 话题表 服务类
...@@ -28,8 +26,10 @@ public interface ITopicService extends IService<Topic> { ...@@ -28,8 +26,10 @@ public interface ITopicService extends IService<Topic> {
/** /**
* 检索话题 * 检索话题
* @param keywords * @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 ...@@ -55,9 +55,11 @@ public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements
} }
@Override @Override
public List<Topic> searchTopics(String keywords) { public IPage<Topic> searchTopics(String keywords, Integer pageNumber, Integer pageSize) {
IPage<Topic> page = new Page<>(pageNumber, pageSize);
return topicMapper.searchTopics(keywords); 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