0

这是jsp页面:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="kendo" uri="http://www.kendoui.com/jsp/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:url value="/web/grid/editing-popup/create.html" var="createUrl"/>
<c:url value="/web/grid/editing-popup/read.html" var="readUrl"/>
<c:url value="/web/grid/editing-popup/update.html" var="updateUrl"/>
<c:url value="/web/grid/editing-popup/destroy.html" var="destroyUrl"/>
<%--
  Created by IntelliJ IDEA.
  User: Rooyan
  Date: 5/26/13
  Time: 4:07 PM
  To change this template use File | Settings | File Templates.
--%>
<html>
<head>
    <link href="../../Styles/examples-offline.css" rel="stylesheet">
    <link href="../../Styles/kendo.common.min.css" rel="stylesheet">
    <link href="../../Styles/kendo.metro.min.css" rel="stylesheet">
    <link href="../../Styles/kendo.rtl.min.css" rel="stylesheet">

    <script src="../../Scripts/jquery.min.js"></script>
    <script src="../../Scripts/kendo.web.min.js"></script>
    <script src="../../Scripts/console.js"></script>
    <link href="../../Styles/Home.css" rel="stylesheet" type="text/css"/>
    <link href="../../Styles/Menu.css" rel="stylesheet" type="text/css"/>
    <link href="../../Styles/jquery-ui-1.10.0.custom.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../../Scripts/jquery-ui-1.10.0.custom.js"></script>
    <title></title>
</head>
<body>
<kendo:grid name="students" sortable="true" selectable="true" scrollable="true"
            groupable="true"
            pageable="true" height="450" width="100">
    <kendo:grid-editable mode="popup"/>
    <kendo:grid-toolbar>
        <kendo:grid-toolbarItem name="create" text="ایجاد رکورد جدید"/>
    </kendo:grid-toolbar>
    <kendo:dataSource pageSize="10">
        <kendo:dataSource-transport>
            <kendo:dataSource-transport-read
                    url="${readUrl}" dataType="json" contentType="application/json" type="POST"/>
            <kendo:dataSource-transport-create
                    url="${createUrl}" dataType="json" contentType="application/json" type="POST"/>
            <kendo:dataSource-transport-update
                    url="${updateUrl}" dataType="json" contentType="application/json" type="POST"/>
            <kendo:dataSource-transport-destroy
                    url="${destroyUrl}" dataType="json" contentType="application/json" type="POST"/>
            <kendo:dataSource-transport-parameterMap>
                <script>
                    function parameterMap(options, type) {
                        return JSON.stringify(options);
                    }
                </script>
            </kendo:dataSource-transport-parameterMap>
        </kendo:dataSource-transport>
        <kendo:dataSource-schema>
            <kendo:dataSource-schema-model id="id">
                <kendo:dataSource-schema-model-fields>
                    <kendo:dataSource-schema-model-field name="firstName" type="string">
                        <kendo:dataSource-schema-model-field-validation required="true"/>
                    </kendo:dataSource-schema-model-field>
                    <kendo:dataSource-schema-model-field name="lastName" type="string">
                    </kendo:dataSource-schema-model-field>
                </kendo:dataSource-schema-model-fields>
            </kendo:dataSource-schema-model>
        </kendo:dataSource-schema>
    </kendo:dataSource>
    <kendo:grid-columns>
        <kendo:grid-column>
            <kendo:grid-column-command>
                <kendo:grid-column-commandItem name="edit" text="ویرایش"/>
            </kendo:grid-column-command>
        </kendo:grid-column>
        <kendo:grid-column field="firstName" title="نام" width="30%"/>
        <kendo:grid-column field="lastName" title="نام خانوادگی" width="40%"/>
        <kendo:grid-column>
            <kendo:grid-column-command>
                <kendo:grid-column-commandItem name="destroy" text="حذف"/>
            </kendo:grid-column-command>
        </kendo:grid-column>
    </kendo:grid-columns>
</kendo:grid>
</body>
</html>

这是我的spring mvc控制器:

package Rooyan.controller;

import Rooyan.Interfaces.StudentService;
import com.google.gson.Gson;
import model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Rooyan
 * Date: 5/26/13
 * Time: 8:41 AM
 * To change this template use File | Settings | File Templates.
 */
@Controller("grid-editing-popup-controller")
@RequestMapping(value="/web/grid")
public class GridController {
    @Autowired
    StudentService studentService;

    @RequestMapping(value="/editing-popup", method = RequestMethod.GET)
    public String index() {
        return "hello";
    }


    @RequestMapping(value = "/editing-popup/read", method = RequestMethod.POST)
    public @ResponseBody List<Student> read() {
//        return studentService.getList();
        List<Student> lst = new ArrayList<Student>();
        Student std1 = new Student();
        Student std2 = new Student();
        Student std3 = new Student();

        std1.setId(1);
        std1.setFirstName("Ali");
        std1.setLastName("Mousavy");
        lst.add(std1);

        std2.setId(2);
        std2.setFirstName("Javad");
        std2.setLastName("Ahmadvand");
        lst.add(std2);

        std3.setId(3);
        std3.setFirstName("Aboutaleb");
        std3.setLastName("Hashemi");
        lst.add(std3);

        return lst;
    }

    @RequestMapping(value = "/editing-popup/update", method = RequestMethod.POST)
    public @ResponseBody Student update(@RequestBody Map<String, Object> model) {
        Student target = new Student();

        target.setFirstName((String)model.get("firstName"));
        target.setLastName((String)model.get("lastName"));

        studentService.UpdateEntity(target);
        return target;
    }

    @RequestMapping(value = "/editing-popup/create", method = RequestMethod.POST)
    public @ResponseBody Student create(@RequestBody Map<String, Object> model) {
        Student target = new Student();

        target.setFirstName((String)model.get("firstName"));
        target.setLastName((String)model.get("lastName"));

        studentService.InsertEntity(target);
        return target;
    }

    @RequestMapping(value = "/editing-popup/destroy", method = RequestMethod.POST)
    public @ResponseBody Student destroy(@RequestBody Map<String, Object> model) {
        Student target = new Student();

        target.setId(Integer.parseInt(model.get("id").toString()));

        studentService.DeleteEntity(target);

        return target;
    }




}

问题是网格是空的,而剑道网站上的示例正在使用此代码并且它在那里工作:http ://demos.kendoui.c​​om/web/grid/editing-popup.html

readurl 不起作用,但创建 url 工作正常!当我按下插入按钮(在网格上)时,会出现用于添加新记录的弹出窗口,单击其按钮后,它将记录插入到我的数据库中。

问题出在哪里?!

4

1 回答 1

1

你应该试试 :

@RequestMapping(value = "/editing-popup/read", method = RequestMethod.GET) 

代替POST

于 2013-07-08T09:16:07.463 回答