From fc768aa566d2d43b5b92c40c2ce7f48c34128428 Mon Sep 17 00:00:00 2001 From: jyx <1584081113@qq.com> Date: Thu, 10 Jan 2019 23:10:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=8C=E6=88=90=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=B3=A8=E5=86=8C=E8=B7=B3=E8=BD=AC=E5=88=B0=E9=A6=96?= =?UTF-8?q?=E9=A1=B5=E5=B9=B6=E5=B1=95=E7=A4=BA=E4=BA=A7=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/demo/loginService/UserController.java | 7 ++++--- .../controller/SearchServiceController.java | 15 +++++++++++++-- .../service/ProductSearchService.java | 1 + .../service/impl/ProductSearchServiceImpl.java | 5 ++++- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/demo/src/main/java/com/example/demo/loginService/UserController.java b/demo/src/main/java/com/example/demo/loginService/UserController.java index 94ae1c5..22ad6ec 100644 --- a/demo/src/main/java/com/example/demo/loginService/UserController.java +++ b/demo/src/main/java/com/example/demo/loginService/UserController.java @@ -4,6 +4,7 @@ import com.example.demo.bean.User; import com.example.demo.loginService.API.impl.UserServiceImpl; 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.PostMapping; import javax.servlet.ServletException; @@ -21,7 +22,7 @@ public class UserController extends HttpServlet { @Autowired private UserServiceImpl userServiceImpl; - @PostMapping("/login") + @GetMapping("/login") public String handle(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException { String userName = request.getParameter("userName"); String userPwd = request.getParameter("userPwd"); @@ -30,8 +31,8 @@ public class UserController extends HttpServlet { if(user.getUserPwd().equals(userPwd)){ HttpSession session=request.getSession(); session.setAttribute("user",user); - return "redirect:index.html"; - //request.getRequestDispatcher("/").forward(request,response); + //request.getRequestDispatcher("index.html").forward(request,response); + return "index"; } else{ return "/userPwdError"; diff --git a/demo/src/main/java/com/example/demo/searchService/controller/SearchServiceController.java b/demo/src/main/java/com/example/demo/searchService/controller/SearchServiceController.java index 8670672..edd6e8e 100644 --- a/demo/src/main/java/com/example/demo/searchService/controller/SearchServiceController.java +++ b/demo/src/main/java/com/example/demo/searchService/controller/SearchServiceController.java @@ -6,7 +6,10 @@ import com.example.demo.searchService.service.ProductSearchService; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +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.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.ServletException; @@ -19,7 +22,9 @@ import java.util.List; @Controller public class SearchServiceController extends HttpServlet { + @Autowired private ProductSearchService productSearchService; + @RequestMapping("/search") public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); @@ -45,7 +50,13 @@ public class SearchServiceController extends HttpServlet { response.getWriter().print(json); } - public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{ - doPost(request,response); + + @PostMapping("/showIndex") + public void showPro(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{ + List products = productSearchService.findByCount(); + String json = JSONObject.toJSONString(products); + System.out.println(json); + response.setCharacterEncoding("utf-8"); + response.getWriter().print(json); } } diff --git a/demo/src/main/java/com/example/demo/searchService/service/ProductSearchService.java b/demo/src/main/java/com/example/demo/searchService/service/ProductSearchService.java index f681cc1..1896e6f 100644 --- a/demo/src/main/java/com/example/demo/searchService/service/ProductSearchService.java +++ b/demo/src/main/java/com/example/demo/searchService/service/ProductSearchService.java @@ -4,6 +4,7 @@ import com.example.demo.bean.Product; import java.util.List; + public interface ProductSearchService { //按关键字查询 List findByNameLike(String productName); diff --git a/demo/src/main/java/com/example/demo/searchService/service/impl/ProductSearchServiceImpl.java b/demo/src/main/java/com/example/demo/searchService/service/impl/ProductSearchServiceImpl.java index 96c33fc..054c52f 100644 --- a/demo/src/main/java/com/example/demo/searchService/service/impl/ProductSearchServiceImpl.java +++ b/demo/src/main/java/com/example/demo/searchService/service/impl/ProductSearchServiceImpl.java @@ -5,15 +5,17 @@ import com.example.demo.Dao.usageDateMapper; import com.example.demo.bean.Product; import com.example.demo.searchService.service.ProductSearchService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; +@Service public class ProductSearchServiceImpl implements ProductSearchService { @Autowired productMapper productMapper; + @Autowired usageDateMapper usageDateMapper; - Product product; @Override public List findByNameLike(String productName){ @@ -32,6 +34,7 @@ public class ProductSearchServiceImpl implements ProductSearchService { @Override public List findByCount(){ + Product product = new Product(); List productList = new ArrayList(); List listusage = usageDateMapper.selectByCount(); int[] arr = listusage.stream().mapToInt(Integer::valueOf).toArray();