package com.kwan.shuyu.controller; import com.kwan.shuyu.service.ContentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import java.io.IOException; import java.util.List; import java.util.Map; @Controller public class ContentController { @Autowired private ContentService contentService; /** * 从京东爬取关键字信息(title、price、src)存放到es中 * * @param keyword * @return * @throws Exception */ @GetMapping("/parse") @ResponseBody public Boolean parse(@RequestParam(value = "keyword") String keyword) throws Exception { return contentService.parseContent(keyword); } /** * 从es中查询相关的信息 参数一:关键字 参数二:页码 参数三:显示条数 * * @param keyword * @param pageNo * @param pageSize * @return * @throws IOException */ @GetMapping("/search/{keyword}/{pageNo}/{pageSize}") @ResponseBody public List> search(@PathVariable("keyword") String keyword, @PathVariable("pageNo") int pageNo, @PathVariable("pageSize") int pageSize) throws IOException { if (pageNo == 0) { pageNo = 1; } if (pageSize == 0) { pageSize = 5; } return contentService.searchPage(keyword, pageNo, pageSize); } @GetMapping("/parse/add2es") public String test(String keyword) { System.out.println(keyword); return "redirect:/parse/" + keyword; } }