Ril*_*ark 6 gwt requestfactory
有没有办法使用RequestFactory在单个请求中创建两个实体?我试过了:
EmployeeRequest request = requestFactory.employeeRequest();
EmployeeProxy newEmployee = request.create(EmployeeProxy.class);
newEmployee.setName("Joe!");
Request<Void> createReq = request.persist().using(newEmployee);
createReq.fire();
EmployeeProxy newEmployee2 = request.create(EmployeeProxy.class);
newEmployee2.setName("Sam!");
Request<Void> createReq2 = request.persist().using(newEmployee2);
createReq2.fire();
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误,表明请求已在进行中.当我做两个单独的EmployeeRequests时:
EmployeeRequest request = requestFactory.employeeRequest();
EmployeeProxy newEmployee = request.create(EmployeeProxy.class);
newEmployee.setName("Joe!");
Request<Void> createReq = request.persist().using(newEmployee);
createReq.fire();
EmployeeRequest request2 = requestFactory.employeeRequest();
EmployeeProxy newEmployee2 = request2.create(EmployeeProxy.class);
newEmployee2.setName("Sam!");
Request<Void> createReq2 = request2.persist().using(newEmployee2);
createReq2.fire();
Run Code Online (Sandbox Code Playgroud)
然后从浏览器发出两个单独的请求.我希望RequestFactory中的某些东西可以合并多个请求 - 我必须一次创建数百个实体,而且我不想发出数百个请求!
是的,这是可能的.在第一个示例中,只需删除该行即可
createReq.fire();
Run Code Online (Sandbox Code Playgroud)
当您最后调用createReq2.fire()
时,GWT会在一个请求中发送newEmployee和newEmployee2(因为它们都在EmployeeRequest的上下文中持久存在" request
").我个人觉得语义有点奇怪,但这只是我的看法.
Riley的附录:以下语法是等效的,更直观:
EmployeeRequest request = requestFactory.employeeRequest();
EmployeeProxy newEmployee = request.create(EmployeeProxy.class);
newEmployee.setName("Joe!");
request.persist().using(newEmployee);
EmployeeProxy newEmployee2 = request.create(EmployeeProxy.class);
newEmployee2.setName("Sam!");
request.persist().using(newEmployee2);
request.fire();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3827 次 |
最近记录: |