使用ModelMap将变量值传输到html

时间:2018-12-27 13:54:36

标签: java spring

此方法在单击链接时打开一个页面,该链接中我需要message属性的值,但没有添加servlet和jsp,如何显示它?我的html是空的

@GetMapping("/activate/{code}")
public String activate(ModelMap model, @PathVariable String code) {

    boolean isActivated = userService.activateUser(code);
    if (isActivated) {
        model.addAttribute("message", "User Successfully activated");
        System.out.println("Successfully");
    } else System.out.println("Activation code not found");
        model.addAttribute("message", "Activation code not found");
    return "verificationPage";
}

1 个答案:

答案 0 :(得分:2)

尝试使用RedirectAttributes

@GetMapping("/activate/{code}")
public String activate(ModelMap model, @PathVariable String code, RedirectAttributes redirAttrs) {

    redirAttrs.addFlashAttribute("message", "Here is your message");
}