简体   繁体   English

从一种控制器方法到另一种方法的内部转发(Spring-MVC)

[英]Internal forwarding from one controller method to another (Spring-MVC)

I am new to spring so not sure how i can do this.I have to handle 2 use case by using single controller method. 我是春天的新手,所以不确定我该怎么做。我必须使用单控制器方法处理2个用例。

Method is already in place so i can not change the signature of it as it can break all other functionalists, here is the method signature 方法已经存在,因此我无法更改其签名,因为它可能会破坏所有其他功能主义者,这是方法签名

@RequestMapping(value = "/edit-address", method = RequestMethod.POST)
    public @ResponseBody JsonResponse editAddress()

JsonResponse is a custom object with following signature JsonResponse是具有以下签名的自定义对象

private String status;
private Object result;
private String steps;

There is one more requirement where we need to validate this address from third part and based on the return results need to show pop-up. 还有另一个要求,我们需要从第三部分验证此地址,然后根据返回结果显示弹出窗口。 I can easily show popu-up if the method signature was not a custom object, but now not sure how i can do this 如果方法签名不是自定义对象,我可以轻松显示弹出窗口,但现在不确定如何执行此操作

is there a way to achieve any of the followwing 有没有办法实现任何追随者

  1. To send JSP content back to the view in place of JSON object from this method. 通过此方法将JSP内容发送回视图而不是JSON对象。
  2. To internally forward control to another method in controller which can send back view to the UI 在内部将控制转发到控制器中的另一种方法,该方法可以将视图发送回UI

How about just composing this controller in another controller that you can control and delegating the call internally to this controller, this way: 如何将这个控制器组合到另一个可以控制的控制器中,并以这种方式在内部将调用委派给该控制器:

@Controller
public class WrapperController{
    @Autowired JsonResponseController jsonResponseController;

    @RequestMapping("/custom_jspview")
    public String customRequestMapping(..., Model model){
        JsonResponse jsonResponse = this.jsonResponseController.editAddress();
        model.addAttribute("jsonresponse", "jsonResponse");
        return "myview";
    }

    @RequestMapping("/redirectView")
    public String redirectView(){
         return "redirect:/custom_jspview";
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM