如何将请求从jquery jtable发送到spring应用程序

时间:2015-07-27 07:34:35

标签: jquery spring-mvc jtable

这是控制器:

  @RequestMapping(value = "saveDetails", method = RequestMethod.POST)
    public ModelAndView saveDetails(@ModelAttribute("checkPointDetailsBean") CheckPointDetailsBean checkPointDetailsBean, BindingResult bindingResult) throws ParseException {


    System.out.println("ggggggg");

    String statusMsg = null;
    JSONObject objmJSONObject = new JSONObject();
    try {

        statusMsg = checkPointDetailsBo.saveDetails(checkPointDetailsBean);
        if ("Success".equals(statusMsg)) {
            objmJSONObject = getJSONObject(true, statusMsg);
        } else {
            statusMsg = bindingResult.getNestedPath().concat("savingFailed");
            objmJSONObject = getJSONObject(false, statusMsg);
        }
    } catch (Exception e) {

        statusMsg = bindingResult.getNestedPath().concat("savingFailed");
        objmJSONObject = getJSONObject(false, statusMsg);
    }

    ModelAndView mv = new ModelAndView("orgnizationTree");
    mv.addObject("orgnizationTree", objmJSONObject);

    return mv;
}

private JSONObject getJSONObject(boolean status, String useMaessage) {

    JSONObject objmStatusObject = new JSONObject();
    JSONObject objmErrorMessageObject = null;
    if (status) {
        objmStatusObject.put("success", status);
        objmErrorMessageObject = new JSONObject();
        objmErrorMessageObject.put("reason", useMaessage);
        objmStatusObject.accumulate("errors", objmErrorMessageObject);
    } else {
        objmStatusObject.put("success", false);
        objmErrorMessageObject = new JSONObject();
        objmErrorMessageObject.put("reason", useMaessage);
        objmStatusObject.accumulate("errors", objmErrorMessageObject);
    }

    return objmStatusObject;
}

这是我的js:

$(document).ready(function() {
    $('#CPValueTableContainer').jtable({
        title : 'CheckPointValue List',
                     selecting: "true",
                     selectingCheckboxes: "true",
                     multiselect:"true",
                     type: 'GET',
                     dataType: 'json',
        actions : {
            listAction : 'Controller?action=list',
            createAction : 'saveDetails',
            updateAction : 'Controller?action=update',
            deleteAction : 'Controller?action=delete'
        },
        fields : {
            checkPointValue : {
                title : 'CheckPointValue',
                width : '30%',
                key : true,
                list : true,
                edit : false,
                create : true
            }
        }
    });
    $('#CPValueTableContainer').jtable('load');
});

0 个答案:

没有答案