_在java中:
_Ajax请求中不能使用Model传递到页面;(没有效果)
使用了@ResponseBoby的注解称之为Ajax请求,表示不返回指定的页面;
@RequestMapper("/index.do")
@ResponseBoby
public Integer methodName(Model model){
model.addAttribute("values",values);//这个model在页面上获取不到的,因为他是一个Ajax请求(方法上贴了@ResponseBoby注解的方法)
return SUCCESS;
}
_前台页面中的$.post(),$.get(),$.ajax()这个三个方法都是ajax方法,不能返回指定的页面;
在前台页面,要返回指定的页面,只能使用普通的请求方式;比如:window.location.href = "指定的地址";
远程桌面的window命令行: mstsc.exe
//========================================================
_Java中:json字符串转对象的方法/解析JSON字符串:
使用Google中的Gson对象;
Gson gson =new Gson();
JsonParser parser =new JsonParser();
JsonArray Jarray =parser.parse(jsonStr).getAsJsonArray();//传递一个json字符串
for (JsonElement obj :Jarray) {//迭代
//Prescription prescription =gson.fromJson(obj,Prescription.class);//迭代需要转换的对象;将转换为对象之后的值添加到java的集合对象中;
//prescriptions.add(prescription);//添加操作
}
_注意:使用Google中的Gson对象,需要在MAVEN中导入对应的依赖配置:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
_案例:需要解析的json字符串信息:
![](https://img.haomeiwen.com/i8123324/fe1df9905e56e5dd.png)
![](https://img.haomeiwen.com/i8123324/7daa8c3823a8419b.png)
![](https://img.haomeiwen.com/i8123324/501f4f0d22772921.png)
![](https://img.haomeiwen.com/i8123324/56bdbfe47b5b6628.png)
网友评论