();
+
+ /**
+ * 定义一个切入点. 解释下:
+ *
+ * ~ 第一个 * 代表任意修饰符及任意返回值. ~ 第二个 * 任意包名 ~ 第三个 * 代表任意方法.
+ *
+ *
~ 第四个 * 定义在web包或者子包 ~ 第五个 * 任意方法 ~ .. 匹配任意数量的参数. execution(*
+ * xiao.ze.demo.service.impl.*.*(..))
+ */
+ @Pointcut("execution(* com.rymcu.forest.*.api.*.*.*(..))")
+ public void webLog() {
+ }
+
+ @Before("webLog()")
+ public void doBefore(JoinPoint joinPoint) {
+
+ startTime.set(System.currentTimeMillis());
+
+ // 接收到请求,记录请求内容
+ logger.info("WebLogAspect.doBefore()");
+ ServletRequestAttributes attributes =
+ (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ HttpServletRequest request = attributes.getRequest();
+
+ // 记录下请求内容
+ logger.info("URL : " + request.getRequestURL().toString());
+ logger.info("HTTP_METHOD : " + request.getMethod());
+ logger.info("IP : " + request.getRemoteAddr());
+ logger.info(
+ "CLASS_METHOD : "
+ + joinPoint.getSignature().getDeclaringTypeName()
+ + "."
+ + joinPoint.getSignature().getName());
+ logger.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
+
+ // 获取所有参数方法一:
+ Enumeration enu = request.getParameterNames();
+ while (enu.hasMoreElements()) {
+ String paraName = (String) enu.nextElement();
+ logger.info(paraName + ": " + request.getParameter(paraName));
+ }
+ }
+
+ @AfterReturning("webLog()")
+ public void doAfterReturning(JoinPoint joinPoint) {
+
+ // 处理完请求,返回内容
+ logger.info("WebLogAspect.doAfterReturning()");
+ logger.info("耗时(毫秒) : " + (System.currentTimeMillis() - startTime.get()));
+ }
+}
+
diff --git a/src/main/java/com/rymcu/forest/lucene/api/SearchController.java b/src/main/java/com/rymcu/forest/lucene/api/SearchController.java
new file mode 100755
index 0000000..fe65fa7
--- /dev/null
+++ b/src/main/java/com/rymcu/forest/lucene/api/SearchController.java
@@ -0,0 +1,72 @@
+package com.rymcu.forest.lucene.api;
+
+import com.rymcu.forest.dto.ArticleDTO;
+import com.rymcu.forest.dto.ArticleSearchDTO;
+import com.rymcu.forest.lucene.mapper.BaikeMapper;
+import com.rymcu.forest.lucene.model.Baike;
+import com.rymcu.forest.lucene.service.SearchService;
+import com.rymcu.forest.service.ArticleService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.servlet.ModelAndView;
+
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/api/v1/lucene")
+public class SearchController {
+ @Autowired private BaikeMapper baikeMapper;
+ @Autowired private SearchService searchService;
+ @Autowired private ArticleService articleService;
+
+ @GetMapping("/index")
+ public String createIndex(int limit, int offset) {
+ // 拉取数据
+ List baikes = baikeMapper.getAllBaike(limit, offset);
+ searchService.write(baikes);
+ return "成功";
+ }
+
+ @GetMapping("/indexArticle")
+ public String createArticleIndex() {
+ // 拉取数据
+ List list = articleService.findArticles(new ArticleSearchDTO());
+ searchService.writeArticle(list);
+ return "成功";
+ }
+
+ /**
+ * 搜索,实现高亮
+ *
+ * @param q
+ * @return
+ * @throws Exception
+ */
+ @GetMapping("/search/{q}")
+ public List