ContentController.java 1.9 KB
Newer Older
1 2 3 4 5 6 7
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;
8
import org.springframework.web.bind.annotation.RequestParam;
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
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
     */
28
    @GetMapping("/parse")
29
    @ResponseBody
30
    public Boolean parse(@RequestParam(value = "keyword") String keyword) throws Exception {
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
        return contentService.parseContent(keyword);
    }

    /**
     * 从es中查询相关的信息 参数一:关键字 参数二:页码 参数三:显示条数
     *
     * @param keyword
     * @param pageNo
     * @param pageSize
     * @return
     * @throws IOException
     */
    @GetMapping("/search/{keyword}/{pageNo}/{pageSize}")
    @ResponseBody
    public List<Map<String, Object>> 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;
    }
}