Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 420ece4

Browse files
committedAug 26, 2017
standard curd jqgrid
1 parent 3c55cef commit 420ece4

File tree

6 files changed

+251
-57
lines changed

6 files changed

+251
-57
lines changed
 

‎README.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ vuejs 增删改查的demo,自动建表 <br>
2727
2828
jqgrid 数据展示
2929
30-
jqgrid 增删改查
30+
jqgrid 增删改查:
31+
{
32+
jqgrid 标准的修改流程(更加优雅):http://localhost/user/jqgridDemo.html
33+
jqgrid 自定义按钮修改(自定义):http://localhost/user/orders.html
34+
}
35+
3136
3237
jqgrid [合并单元格:](http://www.cnblogs.com/puke/archive/2012/10/17/2728435.html)
3338
请查看效果:http://localhost/user/merge.html
@@ -98,6 +103,56 @@ vuejs 增删改查的demo,自动建表 <br>
98103
}
99104
```
100105

106+
Jqgrid 自动提示
107+
```javascript
108+
dataInit : function (element)
109+
{
110+
$(element).attr("autocomplete", "off").typeahead(
111+
{
112+
appendTo : "body",
113+
source : function (query, proxy)
114+
{
115+
$.ajax(
116+
{
117+
url : '/autoJson?callback=?',
118+
dataType : "jsonp",
119+
data :
120+
{
121+
term : query
122+
},
123+
success : proxy
124+
}
125+
);
126+
}
127+
}
128+
);
129+
}
130+
```
131+
对应的后台接口为:
132+
```java
133+
@ResponseBody
134+
@RequestMapping(value = "/autoJson", method = RequestMethod.GET)
135+
public JSONPObject autoScriptUpdate(@RequestParam("term") String query,
136+
@RequestParam(value ="callback", required=true) String callback,
137+
@RequestParam(value ="_", required=true) String line){
138+
139+
List<Order> orders = orderRepository.findAll();
140+
logger.info("autoJson run....");
141+
logger.info(callback);
142+
143+
List<Entry> list = new ArrayList<>();
144+
for (Order order : orders) {
145+
if(order.getProduceName().contains(query)){
146+
String str = order.getProduceName();
147+
list.add(new Entry(str,str));
148+
}
149+
}
150+
System.out.println(list);
151+
152+
return new JSONPObject(callback, list);
153+
}
154+
```
155+
101156

102157

103158

‎src/main/java/com/example/demo/bean/Order.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public class Order implements Serializable {
7676
private Double price;
7777

7878

79-
8079
private String headPortrait;
8180

8281

‎src/main/java/com/example/demo/controller/AutoCompleteController.java

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package com.example.demo.controller;
22

33
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.HashMap;
46
import java.util.List;
7+
import java.util.Map;
58

9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
import org.springframework.beans.factory.annotation.Autowired;
612
import org.springframework.stereotype.Controller;
713
import org.springframework.web.bind.annotation.RequestMapping;
814
import org.springframework.web.bind.annotation.RequestMethod;
@@ -11,19 +17,25 @@
1117

1218
import com.example.demo.bean.Order;
1319
import com.example.demo.repository.OrderRepository;
20+
import com.fasterxml.jackson.databind.util.JSONPObject;
1421

1522
@Controller
1623
public class AutoCompleteController {
1724

25+
private static final Logger logger = LoggerFactory.getLogger(AutoCompleteController.class);
26+
27+
@Autowired
1828
private OrderRepository orderRepository;
1929

2030
//http://www.guriddo.net/demo/bootstrap/
2131

32+
@ResponseBody
2233
@RequestMapping(value = "/autoScript", method = RequestMethod.GET)
2334
public String autoScript(@RequestParam("term") String query,
24-
@RequestParam("element") String element,
25-
@RequestParam(value ="callback", required=true) String callback,
26-
@RequestParam(value ="_", required=true) String line){
35+
@RequestParam("element") String element,
36+
@RequestParam(value ="callback", required=true) String callback,
37+
@RequestParam(value ="_", required=true) String line){
38+
logger.info("autoScript run....");
2739
StringBuffer str = new StringBuffer();
2840
str.append("<script type='text/javascript'>jQuery(document).ready(function() {if(jQuery.ui) { if(jQuery.ui.autocomplete){jQuery('ShipName').autocomplete({'appendTo':'body','disabled':false,'delay':300,'minLength':1,'source':function (request, response)");
2941
str.append("{");
@@ -49,6 +61,7 @@ public String autoScript(@RequestParam("term") String query,
4961
@RequestMapping(value = "/autoCompleteStr", method = RequestMethod.GET)
5062
public List<Entry> autoCompleteStr(@RequestParam("term") String query, @RequestParam("element") String element){
5163
List<Order> orders = orderRepository.findAll();
64+
logger.info("autoCompleteStr run....");
5265

5366
List<Entry> list = new ArrayList<>();
5467
for (Order order : orders) {
@@ -60,6 +73,51 @@ public List<Entry> autoCompleteStr(@RequestParam("term") String query, @Request
6073
return list;
6174
}
6275

76+
@ResponseBody
77+
@RequestMapping(value = "/autoJson", method = RequestMethod.GET)
78+
public JSONPObject autoScriptUpdate(@RequestParam("term") String query,
79+
@RequestParam(value ="callback", required=true) String callback,
80+
@RequestParam(value ="_", required=true) String line){
81+
82+
List<Order> orders = orderRepository.findAll();
83+
logger.info("autoJson run....");
84+
logger.info(callback);
85+
86+
List<Entry> list = new ArrayList<>();
87+
for (Order order : orders) {
88+
if(order.getProduceName().contains(query)){
89+
String str = order.getProduceName();
90+
list.add(new Entry(str,str));
91+
}
92+
}
93+
System.out.println(list);
94+
95+
return new JSONPObject(callback, list);
96+
}
97+
98+
99+
@ResponseBody
100+
@RequestMapping("/amountSelect")
101+
public String amountSelect(){
102+
StringBuffer str = new StringBuffer();
103+
List<Order> orders = orderRepository.findAll();
104+
Map<Integer, Integer> map = new HashMap<>();
105+
List<Integer> list = new ArrayList<>();
106+
for (Order order : orders) {
107+
Integer stockAmount = order.getStockAmount();
108+
if(!map.containsKey(stockAmount)){
109+
list.add(stockAmount);
110+
map.put(stockAmount, stockAmount);
111+
}
112+
}
113+
Collections.sort(list);
114+
115+
for (Integer i : list) {
116+
str.append(i+":"+i+";");
117+
}
118+
return str.toString();
119+
}
120+
63121
class Entry{
64122
String id;
65123

@@ -84,6 +142,11 @@ public String getName() {
84142
public void setName(String name) {
85143
this.name = name;
86144
}
145+
146+
@Override
147+
public String toString() {
148+
return "Entry [id=" + id + ", name=" + name + "]";
149+
}
87150

88151
}
89152

‎src/main/java/com/example/demo/controller/IndexController.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ public List<Role> loadRoles(@RequestParam("id") Long id) {
166166
@RequestMapping(value="/modifyProduct", method=RequestMethod.POST)
167167
public CustomGenericResponse modify(@RequestParam("id") Long orderId, @RequestParam("oper") String operation , Order order){
168168
Order save=null;
169+
// Long orderId =null;
170+
// if(orderid.equals("_empty")){
171+
// orderId = null;
172+
// }else{
173+
// orderId = Long.valueOf(orderid);
174+
// }
169175
if(orderId != null && operation.equals("edit")){
170176
order.setOrderId(orderId);
171177
System.out.println("modify: "+order);
@@ -186,15 +192,60 @@ public CustomGenericResponse modify(@RequestParam("id") Long orderId, @RequestPa
186192
CustomGenericResponse response = new CustomGenericResponse();
187193
response.setSuccess(true);
188194
response.setMessage("Action successful!");
195+
logger.info("modify order success...");
189196
return response;
190197

191198
}
192199
}
193200
CustomGenericResponse response = new CustomGenericResponse();
194201
response.setSuccess(false);
195202
response.setMessage("Action failure!");
203+
logger.info("modify order failed...");
196204
return response;
197205
}
206+
207+
// @ResponseBody
208+
// @RequestMapping(value="/modifyProduct", method=RequestMethod.POST)
209+
// public CustomGenericResponse modify(@RequestParam("id") String orderid, @RequestParam("oper") String operation , Order order){
210+
// Order save=null;
211+
// Long orderId =null;
212+
// if(orderid.equals("_empty")){
213+
// orderId = null;
214+
// }else{
215+
// orderId = Long.valueOf(orderid);
216+
// }
217+
// if(orderId != null && operation.equals("edit")){
218+
// order.setOrderId(orderId);
219+
// System.out.println("modify: "+order);
220+
// save = orderRepository.saveAndFlush(order);
221+
// }else if(null == orderId && operation.equals("add")){
222+
// System.out.println("add: "+ order);
223+
// save = orderRepository.save(order);
224+
// }else if(null != orderId && operation.equals("del")){
225+
// System.out.println("del: "+ order);
226+
// orderRepository.delete(orderId);
227+
// //save 成功删除后不可以为空
228+
// save = order;
229+
// }
230+
//
231+
// if(null != save){
232+
// Boolean success = save!=null;
233+
// if (success == true) {
234+
// CustomGenericResponse response = new CustomGenericResponse();
235+
// response.setSuccess(true);
236+
// response.setMessage("Action successful!");
237+
// logger.info("modify order success...");
238+
// return response;
239+
//
240+
// }
241+
// }
242+
// CustomGenericResponse response = new CustomGenericResponse();
243+
// response.setSuccess(false);
244+
// response.setMessage("Action failure!");
245+
// logger.info("modify order failed...");
246+
// return response;
247+
// }
248+
198249

199250
/**
200251
* 分页的核心逻辑:

‎src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
1616
spring.jpa.database=mysql
1717
spring.jpa.show-sql=false
1818

19-
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&connectTimeout=60000&socketTimeout=60000&autoReconnect=true&autoReconnectForPools=true&failOverReadOnly=false
19+
spring.datasource.url=jdbc:mysql://192.168.1.111:3306/test?useUnicode=true&characterEncoding=UTF-8&connectTimeout=60000&socketTimeout=60000&autoReconnect=true&autoReconnectForPools=true&failOverReadOnly=false
2020
spring.datasource.username=root
2121
spring.datasource.password=root
2222
spring.datasource.driverClassName=com.mysql.jdbc.Driver

0 commit comments

Comments
 (0)
Please sign in to comment.