Angular 代码不会通过将 id 传递给 JAVA(使用 Spring)来删除 json
Angular code doesn't delete json by passing id to JAVA (with Spring)
我的应用程序应该使用 ID 删除 一个 Session 对象,我使用 [=] 从 Angular 传递到 Java class 38=]映射。它不太管用。如果从 UI 完成,则不会发生任何事情。我检查了浏览器中的日志:没有错误。然后我检查 Java 中的日志,似乎 angular 没有到达 Java.
如果我从浏览器地址栏使用:rest/session/delete/IDNUMBEROFSESSION,那么它会工作并删除数据(尽管在 returns HTTP 状态 404 之后 - ).有人可以建议我做错了什么吗?非常感谢你!!!
SessionResource.java
@Controller
@RequestMapping("/session")
public class SessionResource {
private static Logger LOG = LoggerFactory.getLogger(SessionResource.class);
@Autowired
private SessionService sessionService;
@RequestMapping(method = RequestMethod.GET, value = "/{id}")
public ResponseEntity<Session> get(@PathVariable String id) {
Session session = sessionService.findById(id);
return new ResponseEntity<Session>(session, HttpStatus.ACCEPTED);
}
// DELETE
@RequestMapping(method = RequestMethod.GET, value = "/delete/{id}")
public void delete(@PathVariable("id") String id) {
System.out.println("Starting to enter request mapping delete and calling sessionService.delete function");
Session session = sessionService.findById(id);
sessionService.delete(session);
}
}
Resource.JS 使用此代码:
app.factory('SessionResource', function ($resource) {
return $resource('rest/session/:sessionId',
{
speakerId: '@sessionId'
},
{
'update': { method: 'PUT' },
'delete': { method: 'GET' , isArray: true}
});
});
您需要通过传递 sessionId
参数来调用 SessionResource
的删除方法。
SessionResource.delete({sessionId: data.id}, function(response){
callback(response);
})
我的应用程序应该使用 ID 删除 一个 Session 对象,我使用 [=] 从 Angular 传递到 Java class 38=]映射。它不太管用。如果从 UI 完成,则不会发生任何事情。我检查了浏览器中的日志:没有错误。然后我检查 Java 中的日志,似乎 angular 没有到达 Java.
如果我从浏览器地址栏使用:rest/session/delete/IDNUMBEROFSESSION,那么它会工作并删除数据(尽管在 returns HTTP 状态 404 之后 - ).有人可以建议我做错了什么吗?非常感谢你!!!
SessionResource.java
@Controller
@RequestMapping("/session")
public class SessionResource {
private static Logger LOG = LoggerFactory.getLogger(SessionResource.class);
@Autowired
private SessionService sessionService;
@RequestMapping(method = RequestMethod.GET, value = "/{id}")
public ResponseEntity<Session> get(@PathVariable String id) {
Session session = sessionService.findById(id);
return new ResponseEntity<Session>(session, HttpStatus.ACCEPTED);
}
// DELETE
@RequestMapping(method = RequestMethod.GET, value = "/delete/{id}")
public void delete(@PathVariable("id") String id) {
System.out.println("Starting to enter request mapping delete and calling sessionService.delete function");
Session session = sessionService.findById(id);
sessionService.delete(session);
}
}
Resource.JS 使用此代码:
app.factory('SessionResource', function ($resource) {
return $resource('rest/session/:sessionId',
{
speakerId: '@sessionId'
},
{
'update': { method: 'PUT' },
'delete': { method: 'GET' , isArray: true}
});
});
您需要通过传递 sessionId
参数来调用 SessionResource
的删除方法。
SessionResource.delete({sessionId: data.id}, function(response){
callback(response);
})