【问题标题】:In spring framework, How to pass the parameters to another controler在spring框架中,如何将参数传递给另一个控制器
【发布时间】:2020-10-09 07:14:01
【问题描述】:

是否可以将参数从一个控制器传递到另一个控制器?

@控制器 公共类 ICentraSrcCtrlLoginController {

@PostMapping("/iCentraSrcCtrlLogin") public ModelAndView iCentraSrcCtrlLoginSubmit(@ModelAttribute ICentraSrcCtrlLogin inp, 模型模型) {

ICentraSrcCtrl iCentraSrcCtrl = new ICentraSrcCtrl();

Map<String, Object> myModel = new HashMap<String, Object>();

myModel.put("iCentraPassWd", inp.getiCentraPassWd());
myModel.put("UsrPassWd", inp.getUsrPassWd());
myModel.put("iCentraSrcCtrl", iCentraSrcCtrl);

return new ModelAndView("redirect:/iCentraSrcCtrl", "iCentraSrcCtrl", myModel);


}

}

@控制器 公共类 ICentraSrcCtrlController {

@GetMapping("/iCentraSrcCtrl") public String iCentraSrcCtrlForm(模型模型) {

logger.info("iCentraSrcCtrlForm");

Map<String, Object> myModel = model.asMap();
logger.info("iCentraPassWd size: " + myModel.size());
logger.info("iCentraPassWd: " + new Boolean(myModel.containsKey("iCentraPassWd")).toString());

} } 记录器的输出:

ICentraSrcCtrlController:iCentraPassWd 大小:0 ICentraSrcCtrlController : iCentraPassWd: false

【问题讨论】:

    标签: spring-mvc model-view-controller


    【解决方案1】:

    使用 RedirectView 将值传递给新控制器。

    ra.addFlashAttribute("iCentraPassWd", inp.getiCentraPassWd());
    ra.addFlashAttribute("UsrPassWd", inp.getUsrPassWd());
    RedirectView redirectView = new RedirectView();
    redirectView.setContextRelative(true);
    redirectView.setUrl("/iCentraSrcCtrl");
    return redirectView;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-01
      • 2016-07-29
      • 1970-01-01
      • 2020-02-09
      • 2011-02-26
      • 1970-01-01
      • 2015-06-04
      • 1970-01-01
      相关资源
      最近更新 更多