0

我正在做我的 struts 项目,现在我想以 json 格式检索数据。但是我想要获取 json 响应的变量并没有检索到我需要的 json 值。

这是我的动作课

import com.myDrDirect.hbmobj.Doctor;
import com.myDrDirect.order.dao.DoctorDashBoardDao;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import java.util.Map;

public class patientOrderDetails extends ActionSupport {
    private int rows;
    private int total;
    private int records;
    private int page;
    private List recentOrders;
    public String jsonRecentOrderDetails() {

         try{
            Map sessionSingleDoctor = ActionContext.getContext().getSession();
            Doctor SessionObj = (Doctor) sessionSingleDoctor.get("Doctor");

          records = DoctorDashBoardDao.getInstance().getCount();
            //records = 10;
             setRows(Integer.parseInt(getText("number.rows.per.page")));
        //rows = 10;
            int to = (getRows() * getPage());
            int from = (getRows() * (getPage()-1));


            total =(int) Math.ceil((double)records / (double)rows);   
            recentOrders= DoctorDashBoardDao.getInstance().getDoctorRecentOrderDetails(rows,from,SessionObj.getId());


     } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getCause());
            //log.error("Error occured " + e.toString());
            return ERROR;
        }
          return SUCCESS;
     }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getRecords() {
        return records;
    }

    public void setRecords(int records) {
        this.records = records;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public List getRecentOrders() {
        return recentOrders;
    }

    public void setRecentOrders(List recentOrders) {
        this.recentOrders= recentOrders;
    }


}

我的 struts.xml 有

<package name="json" extends="json-default">

            <action name="DashBoardActivityJson" class="com.myDrDirect.doctor.action.patientOrderDetails" method="jsonRecentOrderDetails">
                <result name="success" type="json">
                    <!-- serialize the result property of the action -->                    
                    <param name="includeProperties">recentOrders</param>

                </result>
            </action>
            <action name="grid" >
                <result name="success" >/WEB-INF/doctor/jsonGrid.jsp</result>
            </action>
        </package>

我需要在变量中获取响应,RecentOrders1但此变量不检索 json 数据。当我检索变量时,records我得到了正确的响应。记录者只有列表的总数,但 recentOrder1 返回一个列表。我需要在我的视图页面中获取recentOrder 作为列表。谁能告诉我上述操作或 xml 文件中的问题是什么。请帮忙。

我在这里注意到的一件事是recentOrder 中的返回值是一个列表。我需要将此列表转换为 json 字符串吗?是否有必要或 struts2 自动将我的列表变量更改为 json 字符串?

4

1 回答 1

0

您的操作没有属性RecentOrders1,只有recentOrders.

注意大写和缺少数字。

于 2012-02-06T11:25:34.980 回答