我已经在这个问题上困了一段时间了。我有一个与restdatasource绑定的smartgwt小部件列表网格。我已经将它的URL映射到我的spring服务。但是,我不知道如何在spring服务器端检索JSON dsrequest。甚至我的dispatcher servlet也不包含params。
我的restdatasource源如下:
RestDataSource myDS = new RestDataSource() {
@Override
protected Object transformRequest(DSRequest dsRequest) {
dsRequest.setContentType("application/json");
JavaScriptObject jso = dsRequest.getData();
String s1 = JSON.encode(jso);
return s1;
// return super.transformRequest(dsRequest);
}
@Override
protected void transformResponse(DSResponse response, DSRequest request, Object data) {
super.transformResponse(response, request, data);
}
};然后在此数据源上按如下方式设置操作:
// set the operation on the datasource
OperationBinding fetch = new OperationBinding();
fetch.setOperationType(DSOperationType.FETCH);
fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
OperationBinding add = new OperationBinding();
add.setOperationType(DSOperationType.ADD);
add.setDataProtocol(DSProtocol.POSTMESSAGE);
OperationBinding update = new OperationBinding();
update.setOperationType(DSOperationType.UPDATE);
update.setDataProtocol(DSProtocol.POSTPARAMS);
OperationBinding remove = new OperationBinding();
remove.setOperationType(DSOperationType.REMOVE);
remove.setDataProtocol(DSProtocol.POSTMESSAGE);
myDS.setOperationBindings(fetch, add, update, remove);
myDS.setDataFormat(DSDataFormat.JSON);
// myDS.setDataProtocol(DSProtocol.POSTMESSAGE);在数据源中设置一些字段:
// set the values for the datasource
DataSourceTextField Id = new DataSourceTextField("Id", "Id");
Id.setPrimaryKey(true);
Id.setCanEdit(false);
DataSourceTextField name= new DataSourceTextField("name", "Name");
name.setCanEdit(false);
DataSourceTextField employeeType= new DataSourceTextField("employeeType", "employeeType");
employeeType.setCanEdit(true);
employeeType.setValueMap("Manager", "Associate", "Contractor");将这些字段设置为数据源:
myDS.setFields(Id, name,employeeType);
myDS.setFetchDataURL("/rest/myservice/fetch");
myDS.setAddDataURL("/rest/myservice/add");
myDS.setUpdateDataURL("/rest/myservice/update");
myDS.setRemoveDataURL("/rest/myservice/remove");因此,在用户更改employeeType (因为它是一个下拉列表)的情况下,将发送一个更新请求。我将JSON字符串发送到如下配置的服务器:
@Controller
@RequestMapping("/myservice")
public class MyService {
...fetch
...update
@RequestMapping(value="/update", method=RequestMethod.POST)
@ResponseBody
public String update()
{
}我不能理解如何检索(JSON) dsrequest,因为即使我的DispatcherServlet也没有参数(即使我使用POSTPARAMS)。开发人员控制台显示了正确的请求,但我在服务器端没有收到任何东西。我的spring servlet在web.xml中的配置如下:
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup> </servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>我想我遗漏了一些明显的东西,但是我找不到它。我应该使用@PathVariable还是RequestParams?
发布于 2011-05-17 22:44:09
找到了我自己的答案。希望这对某些人有帮助。
update.setDataProtocol(DSProtocol.POSTPARAMS);至
update.setDataProtocol(DSProtocol.POSTMESSAGE);@Override
protected Object transformRequest(DSRequest dsRequest) {
JavaScriptObject jso = dsRequest.getData();
String s1 = JSON.encode(jso);
return s1;
}@RequestMapping(value="/update", method=RequestMethod.POST)
@ResponseBody public String update(@RequestBody String json) { }https://stackoverflow.com/questions/6026386
复制相似问题