修改controller

master
istars 7 years ago
parent 777aab8e0d
commit 2c7963e1ba

@ -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
//@Controller
@RestController
@RequestMapping("/search")
public class SearchServiceController extends HttpServlet {
@Autowired
private ProductSearchService productSearchService;
@RequestMapping("/search")
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
@RequestMapping(value = "/show",method = RequestMethod.POST)
public List<Product> search(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
List<Product> list = new ArrayList<Product>();
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);
@ -43,9 +47,9 @@ public class SearchServiceController extends HttpServlet {
list = productSearchService.findByCount();
//默认按产品使用的产品的数量由高到低排序
}
String json = JSONObject.toJSONString(list);
response.getWriter().print(json);
// String json = JSONObject.toJSONString(list);
// response.getWriter().print(json);
return list;
}
@PostMapping("/showIndex")

@ -10,7 +10,6 @@
<style type="text/css">
.tb960x90 {display:none!important;display:none}
</style>
<script type="text/javascript" src="js/myorder.js"></script>
<script type="text/javascript" src="js/jquery.min.js" ></script>
</head>
<body>

@ -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 = '<a href="javascript:;" class="aui-list-item"><div class="aui-right-top"></div><div class="aui-list-head" id="proname">'+pro.productName+'</div><div class="aui-flex"><div class="aui-flex-box"><h4>'+pro.productNum+'</h4></div><div class="aui-text-time"></div><div class="aui-button-get"><button id="apply", onclick="location=\'apply.html\'">申请</button> </div></div><div class="aui-dotted"></div></a>';
str = '<a href="javascript:;" class="aui-list-item"><div class="aui-right-top"></div><div class="aui-list-head" id="proname">'+pro.productName+'</div><div class="aui-flex"><div class="aui-flex-box"><h4>'+pro.productNum+'</h4></div><div class="aui-text-time"></div><div class="aui-button-get"><button id="apply", onclick="location=\'apply.html\'">申请</button> </div></div><div class="aui-dotted"></div></a>';
$("#content").append(str);
}

@ -9,22 +9,25 @@
</head>
<body>
<form action="/search" method="post">
<div class="headBox">
<h2 class="titHead">产品信息</h2>
<h3 class="titNeck">内容简介</h3>
<h2 class="titHead">产品搜索</h2>
<!--<h3 class="titNeck">内容简介</h3>-->
<div class="search">
<input id="serch" type="text" placeholder="搜索">
<button id="btn" type="button"></button>
<input name="productName" type="text" placeholder="搜索">
<button name="btn" type="button"></button>
</div>
</div>
<div class="content">
</div>
<div class="footBox">
<input type="button" name="" id="btn2" value="确&nbsp;&nbsp;定" />
<input type="submit" name="action" id="btn2" value="确&nbsp;&nbsp;定" />
</div>
<script type="text/javascript" src="js/jquery.min.js" ></script>
</form>
<script type="text/javascript" src="js/search.js"></script>
</body>

Loading…
Cancel
Save