[英]Spring rest redirect controller to another
i currently have this method: 我目前有这种方法:
@RequestMapping(value = "/{id}/behavior/{behaviorId}", method = RequestMethod.PUT)
private ResponseEntity modifyBehavior(@PathVariable("id") String id, @PathVariable("behaviorId") String behaviorId, @RequestBody BehaviorDto behaviorDto) {
if (aptitudeRepository.findById(id) == null) {
return new ResponseEntity(HttpStatus.BAD_REQUEST);
}
if (aptitudeRepository.findBehaviorById(id, behaviorId) == null) {
return new ResponseEntity(HttpStatus.NOT_FOUND);
} Behavior behavior = new Behavior(behaviorId,behaviorDto.getEn(),behaviorDto.getEs());
return new ResponseEntity(aptitudeRepository.updateBehaviorById(id, behavior), HttpStatus.ACCEPTED);
im handling the request in this method as i like, but my coworkers told me that this method (and other behavior methods should be in their own BehaviorController class. i moved the methods for behavior handling to another class (BehaviorController) and all worked quite as espected. the first methods /aptitude
and /aptitude/{id}
were redirected to the aptitudeController and the other methods like /aptitude/{id}/behavior
and aptitude/{id}/behavior/id
were succesfully redirected to BehaviorController , everything nice. 我按照自己喜欢的方式在此方法中处理请求,但是我的同事告诉我,此方法(以及其他行为方法应在自己的BehaviorController类中。我将用于行为处理的方法移至另一个类(BehaviorController),并且所有方法都可以正常工作可以预期,第一个方法/aptitude
和/aptitude/{id}
被重定向到aptitudeController ,其他方法如/aptitude/{id}/behavior
和aptitude/{id}/behavior/id
被成功重定向到BehaviorController ,一切都很好。
buuuuut now i was told that this methods should be redirected from the AptitudeController to the BehaviorController . buuuuut现在,我被告知该方法应从AptitudeController重定向到BehaviorController 。 along with their @PathVariables and return the other method return (xD sorry for the bad english) 连同它们的@PathVariables一起返回另一个方法return(xD对不起,英语不好)
so it will end something like this: 因此它将结束如下所示:
@RequestMapping(value = "/{id}/behavior/{behaviorId}", method = RequestMethod.PUT)
private ResponseEntity modifyBehavior(@PathVariable("id") String id,
@PathVariable("behaviorId") String behaviorId,
@RequestBody BehaviorDto behaviorDto) {
return *somehowMethodRedirecting*?
can anyone point me in the right direction? 谁能指出我正确的方向?
you create a bean from AptitudeController of BehaviorController and you can pass your values to BehaviorController. 您可以从BehaviorController的AptitudeController创建一个bean,然后可以将值传递给BehaviorController。 In my experience you can not return to BehaviorController. 以我的经验,您无法返回到BehaviorController。
you are calling this method using url from the browser. 您正在使用浏览器中的url调用此方法。 then browser will get response rendering the contents. 然后浏览器将获得响应以呈现内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.