2017-08-15 19 views
0

コントローラが/、もう1つがフォームを送信しています。フォーム登録後に/コントローラにリダイレクトします。ここコントローラでRedirectAttributeによって送信されたパラメータを読み取ることができません

/のための私のコントローラである:

@RequestMapping(value = "/", method = RequestMethod.GET) 
public String mainPage(@RequestParam(value = "registerSuccessful", required = false) boolean registerSuccessful, 
         ModelMap modelMap) throws UnknownHostException { 
    boolean isDeviceRegistered = mainService.isDeviceRegistered(); 
    modelMap.addAttribute("isDeviceRegistered", isDeviceRegistered); 
    modelMap.addAttribute("registerSuccessful", registerSuccessful); 
    return "main"; 
} 

/registerForm用コントローラ:

@RequestMapping(value = "registerForm", method = RequestMethod.POST, produces = "text/plain;charset=UTF-8") 
public String saveDeviceInfo(@ModelAttribute("deviceInfo") DeviceInfo deviceInfo, 
          RedirectAttributes redirectAttributes, 
          BindingResult result, ModelMap modelMap){ 
    mainService.saveDeviceInfo(deviceInfo); 
    redirectAttributes.addFlashAttribute("registerSuccessful", true); 
    return "redirect:/"; 
} 

ご覧の通り、私は/registerSuccessfulの内容を読んだとき、私は属性registerSuccessfulためtrueを送るが、リダイレクト後のハンドラはfalseです。

どうすれば修正できますか?このような

答えて

0

使用@ModelAttribute

@RequestMapping(value = "/", method = RequestMethod.GET) 
public String mainPage(@ModelAttribute(value = "registerSuccessful") boolean registerSuccessful, 
         ModelMap modelMap) throws UnknownHostException { 
    boolean isDeviceRegistered = mainService.isDeviceRegistered(); 
    modelMap.addAttribute("isDeviceRegistered", isDeviceRegistered); 
    modelMap.addAttribute("registerSuccessful", registerSuccessful); 
    return "main"; 
} 
関連する問題