Java项目实战 - solr实现前端商品搜索 Posted on 2018-07-22 | In Java | | 在zheyi-portal工程中实现。 Dao无。 Service1234567891011121314151617181920212223242526@Servicepublic class SearchServiceImpl implements SearchService { @Value("${SEARCH_BASE_URL}") private String SEARCH_BASE_URL; @Override public SearchResult search(String query, int page) { Map<String, String> param = new HashMap<>(); param.put("q", query); param.put("page", page + ""); try { String getString = HttpClientUtil.doGet(SEARCH_BASE_URL, param); TaotaoResult result = TaotaoResult.formatToPojo(getString, SearchResult.class); if (result.getStatus() == 200) { SearchResult searchResult = (SearchResult) result.getData(); return searchResult; } } catch (Exception e) { e.printStackTrace(); } return null; }} Controller1234567891011121314151617181920212223242526272829@Controllerpublic class SearchServiceController { @Autowired private SearchService searchService; @RequestMapping("/search") public String search(@RequestParam("q")String query, @RequestParam(defaultValue="1")Integer page, Model model) { if (query != null) { try { query = new String(query.getBytes("iso8859-1"), "utf-8"); } catch (Exception e) { e.printStackTrace(); } } SearchResult searchResult = searchService.search(query, page); model.addAttribute("query", query); model.addAttribute("totalPages", searchResult.getTotalPageCount()); model.addAttribute("itemList", searchResult.getItemList()); model.addAttribute("page", page); return "search"; }} 欢迎您扫一扫上面的微信公众号,订阅我的博客! 分享创造价值,您的支持将鼓励我继续前行! Donate WeChat Pay Alipay Post author: 唐胡璐 Post link: http://izheyi.com/2018/07/22/Java项目实战-solr实现前端商品搜索/ Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.