jeecg中ajax传值的前端js和后台代码

前端js:

var b=1;

$.ajax({
type : "POST",            --Post请求方式
url : 'orderController.do?wuliao',    --路径
crossDomain : true,          
data: 'id='+b,            --传入的id值
success : function(data) {
data=data.replace("[","");      --返回的data数据
data=data.replace("]","");
var strs= new Array(); //定义一数组
strs=data.split(","); //字符分割
  },
error:function(){
alert("系统错误!");
}
})

 

后台代码:返回的是[aa,bb,cc]类型的

@RequestMapping(params = "wuliao")
@ResponseBody
public void wuliao(HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) throws IOException {
String id=request.getParameter("id"); //接收传入的id值
String aa= jdbcTemplate.queryForObject("select goods_name from wsc_goods where goods_id=?",String.class,Integer.parseInt(id));
int bb=jdbcTemplate.queryForInt("select goods_price from wsc_goods where goods_id=?",Integer.parseInt(id));
String cc=String.valueOf(bb);
String dd= jdbcTemplate.queryForObject("select goods_code from wsc_goods where goods_id=?",String.class,Integer.parseInt(id));
String ff= jdbcTemplate.queryForObject("select goods_model from wsc_goods where goods_id=?",String.class,Integer.parseInt(id));
List<String> list = new ArrayList<String>();
list.add(aa);
list.add(cc);
list.add(dd);
list.add(ff);
JSONArray array = new JSONArray();
array.add(list);
response.getWriter().write(list.toString());

}

 

posted @ 2017-02-07 14:57  许佳挺  阅读(5163)  评论(0编辑  收藏  举报