diff --git a/demo/pom.xml b/demo/pom.xml index 3bc2f42..b65b330 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -103,6 +103,12 @@ tomcat-embed-jasper provided + + org.springframework.boot + spring-boot-starter-web + RELEASE + compile + diff --git a/demo/src/main/java/com/example/demo/Dao/usageDateMapper.java b/demo/src/main/java/com/example/demo/Dao/usageDateMapper.java index 7bc503e..1b8b02c 100644 --- a/demo/src/main/java/com/example/demo/Dao/usageDateMapper.java +++ b/demo/src/main/java/com/example/demo/Dao/usageDateMapper.java @@ -16,7 +16,7 @@ public interface usageDateMapper { @Select("select productNum from usageDate group by productNum order by count(productNum) DESC") - public List selectByCount(); + public List selectByCount(); @Insert("insert into usagedate(checkNum, productNum, userNum," + " bankAccount, bankNum, year, amount, startTime)" + 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 eaf6091..4d9fdef 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 @@ -8,6 +8,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -17,18 +19,20 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -@Controller -public class SearchServiceController extends HttpServlet { +//@Controller +@RestController +@RequestMapping("/search") +public class SearchServiceController{ @Autowired private ProductSearchService productSearchService; - @RequestMapping("/search") - public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { + @RequestMapping(value = "/show",method = RequestMethod.POST) + public List search(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); List list = new ArrayList(); String productName = request.getParameter("productName"); String category = request.getParameter("category"); - float intrate = Integer.parseInt(request.getParameter("intrate")); + //float intrate = Float.parseFloat(request.getParameter("intrate")); if(productName!=null){ list = productSearchService.findByNameLike(productName); @@ -36,24 +40,22 @@ public class SearchServiceController extends HttpServlet { }else if(category!=null){ list = productSearchService.findByCategory(category); //按产品类别搜索 - }else if(intrate!=0){ - list = productSearchService.findByIntrate(intrate); - //按利率排序由低到高 +// }else if(intrate!=0){ +// list = productSearchService.findByIntrate(intrate); +// //按利率排序由低到高 }else{ list = productSearchService.findByCount(); //默认按产品使用的产品的数量由高到低排序 } - String json = JSONObject.toJSONString(list); - response.getWriter().print(json); - + return list; } - @PostMapping("/showIndex") - public void showPro(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{ + @RequestMapping(value = "/showIndex",method = RequestMethod.POST) + public List 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); + return products; + //String json = JSONObject.toJSONString(list); + // response.getWriter().print(json); } } 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 054c52f..ce1d895 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 @@ -36,8 +36,8 @@ public class ProductSearchServiceImpl implements ProductSearchService { public List findByCount(){ Product product = new Product(); List productList = new ArrayList(); - List listusage = usageDateMapper.selectByCount(); - int[] arr = listusage.stream().mapToInt(Integer::valueOf).toArray(); + List listusage = usageDateMapper.selectByCount(); + long [] arr = listusage.stream().mapToLong(t->t.longValue()).toArray(); for(int i=0;i .tb960x90 {display:none!important;display:none} - diff --git a/demo/src/main/resources/static/index.html b/demo/src/main/resources/static/index.html index d88e6d1..6d3ba2c 100644 --- a/demo/src/main/resources/static/index.html +++ b/demo/src/main/resources/static/index.html @@ -178,9 +178,9 @@ setInterval('AutoScroll("#aui-show")', 3000) }); - window.onload(function requestData(){ + $(function () { $.ajax({ - url: "/showIndex", + url: "/search/showIndex", type: "post", dataType: "json", success: function(data){ diff --git a/demo/src/main/resources/static/js/productshow.js b/demo/src/main/resources/static/js/productshow.js index 491b244..bea9696 100644 --- a/demo/src/main/resources/static/js/productshow.js +++ b/demo/src/main/resources/static/js/productshow.js @@ -1,9 +1,11 @@ -window.onload(function requestData(){ +$(function(){ $.ajax({ url: "/search", type: "post", + data: {}, dataType: "json", success: function(data){ + console.log(data);//查看从后台传值内容 /*这个方法里是ajax发送请求成功之后执行的代码*/ showData(data);//我们仅做数据展示 }, @@ -19,7 +21,7 @@ function showData(data) { $("#content").html=null; for (var i = 0; i < data.length; i++) { var pro = data[i]; - var str = '
'+pro.productName+'

'+pro.productNum+'

'; + str = '
'+pro.productName+'

'+pro.productNum+'

'; $("#content").append(str); } diff --git a/demo/src/main/resources/static/search.html b/demo/src/main/resources/static/search.html index 245d7fb..eba380a 100644 --- a/demo/src/main/resources/static/search.html +++ b/demo/src/main/resources/static/search.html @@ -9,22 +9,25 @@ +
-

产品信息

-

内容简介

+

产品搜索

+
- + +
- - +
+