【问题标题】:EXT JS: is it possible to add url to reader and writer in proxyEXT JS:是否可以在代理中添加 url 到 reader 和 writer
【发布时间】:2012-04-29 19:05:40
【问题描述】:

我正在创建一个使用 Spring 3、EXTJS 4、hibernate 3 的简单项目,我想创建一个从数据库中提取数据的 ext 表单,您可以添加、删除和更新此信息。我已经填写了表格,现在我想弄清楚如何在表格中更新客户。

最好的方法是什么?我正在考虑为作者使用与阅读器不同的 url,以便它可以将客户对象传递回我的 java 类以更新数据库

这是我目前填充表单的方式

Ext.onReady(function(){

var store = Ext.create('Ext.data.Store', {
    autoLoad: true,
    autoSync: true,
    model: 'Person',
    proxy: {
        type: 'rest',
        url: 'http://localhost:8080/helloworld/service/web',
        reader: {
            type: 'json' 
        },
        writer: {
            type: 'json',
        }
    },
.....

我想知道是否可以像这样为读者和作者使用不同的网址

Ext.onReady(function(){

var store = Ext.create('Ext.data.Store', {
    autoLoad: true,
    autoSync: true,
    model: 'Person',
    proxy: {
        type: 'rest',

        reader: {
            type: 'json',
            url: 'http://localhost:8080/helloworld/service/web'
        },
        writer: {
            type: 'json',
            url: 'http://localhost:8080/helloworld/service/web/update'
        }
    },
......

这些是我用来填充表单和更新客户的方法

@Controller
@RequestMapping("/web")  
public class Web {

@Autowired
private CustomerService customerService;

@RequestMapping(method=RequestMethod.GET)
public @ResponseBody List<Customer> getCustomers() {
    List<Customer> list = customerService.returnAllCustomers();
    return list;
}

@RequestMapping(value="/update", method=RequestMethod.GET)
public @ResponseBody void updateCustomers(Customer customer) {
    customerService.saveCustomer(customer);
}
......

谢谢

【问题讨论】:

    标签: spring hibernate rest spring-mvc extjs


    【解决方案1】:

    如果您想拥有单独的 URL,您可以切换到使用 AjaxProxy。 Readers 和 Writers 不应配置 URL,因为它们只是解码器和编码器。这是一个例子:

    var store = Ext.create('Ext.data.Store', {
        autoLoad: true,
        autoSync: true,
        model: 'Person',
        proxy: {
            type: 'ajax',
            api: {
                create  : 'http://localhost:8080/helloworld/service/web/create',
                read    : 'http://localhost:8080/helloworld/service/web',
                update  : 'http://localhost:8080/helloworld/service/web/update',
                destroy : 'http://localhost:8080/helloworld/service/web/delete'
            }
            reader: {
                type: 'json'
            },
            writer: {
                type: 'json'
            }
        }
    }
    

    相反,如果您想继续使用 restful 实现,则需要更改服务器端 API 以将创建、读取、更新和销毁方法映射到 POSTGETPUTDELETE 分别。示例:

    @RequestMapping(method=RequestMethod.PUT)
    public @ResponseBody void updateCustomers(Customer customer) {
        customerService.saveCustomer(customer);
    }
    

    【讨论】:

      猜你喜欢
      • 2020-05-17
      • 1970-01-01
      • 1970-01-01
      • 2017-11-02
      • 2019-04-14
      • 2021-03-30
      • 2012-01-08
      • 2015-04-16
      • 2021-11-26
      相关资源
      最近更新 更多