EXT JS:是否可以在代理中为读写器添加url

时间:2012-04-18 11:16:52

标签: spring hibernate rest spring-mvc extjs

我正在创建一个使用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);
}
......

由于

1 个答案:

答案 0 :(得分:3)

如果您想拥有单独的网址,可以切换为使用AjaxProxy。读者和写者不应该配置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以将创建,读取,更新和销毁方法映射到POSTGET,{分别为{1}}和PUT。例如:

DELETE