在处理json对象时
struts.xml的配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<!-- struts.xml文件,有且仅有一个叫struts.xml的文件
作用:配置action
-->
<struts>
<package name="dept" namespace="/" extends="json-default">
<!-- 处理登录 -->
<action name="deptListAction" class="com.hydz.action.DeptAction" method="find">
<result name="json-deptList" type="json">
</result>
</action>
</package>
</struts>
@Controller
public class DeptAction extends ActionSupport{
@Resource
private DeptService deptService;
private Dept dept;
private int total;
private Boolean success;
private List<Dept> deptList;
public String find() {
deptList=deptService.find();
total=deptList.size();
success=true;
//JSONObject jo=new JSONObject();
//JSONArray ja = JSONArray.fromObject(deptList);
//deptList=jo.put("deptlist", ja);//.toString();
return "json-deptList";
}public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
public DeptService getDeptService() {
return deptService;
}
public void setDeptService(DeptService deptService) {
this.deptService = deptService;
}
public Dept getDept() {
return dept;
}
public void setDept(Dept dept) {
this.dept = dept;
}
public List<Dept> getDeptList() {
return deptList;
}
public void setDeptList(List<Dept> deptList) {
this.deptList = deptList;
}
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
}
在页面接受到的数据为
- dept: null
- deptList: [{deptName:的说法都是, deptNum:100}, {deptName:第三方, deptNum:101}, {deptName:多少分但是, deptNum:102}]
- deptService: {}
- success: true
- total: 3