简体   繁体   English

Spring Rest将控制器重定向到另一个

[英]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}/behavioraptitude/{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.

相关问题 Spring控制器重定向到另一个模块 - Spring controller redirect to another module Spring Controller重定向到另一个页面 - Spring Controller redirect to another page 如何将文件重定向到另一个spring控制器? - How to redirect file to another spring controller? 无法从一个控制器重定向到另一控制器-Spring MVC - Unable to redirect from one controller to another controller-Spring MVC 将 POST 请求从一个控制器重定向到另一个控制器 Spring Boot - Redirect to a POST request from one controller to another controller Spring Boot Spring REST,使用参数将请求重定向到另一个应用程序(SSO,SAML) - Spring REST, redirect request to another application with params (SSO, SAML) Spring Web 应用程序控制器基于另一个端点的结果重定向 - Spring web app controller redirect based on results of another endpoint 下载或重定向错误消息到 Spring Web MVC 中的另一个控制器操作 - Download or redirect with error message to another controller action in Spring web MVC 如何使用Spring MVC在控制器中重定向另一个JSP页面? - how to redirect another jsp page in controller using spring MVC? 无法使用路径变量重定向到 Spring MVC 中的另一种控制器方法 - Not able to redirect to another method of controller in Spring MVC using path variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM