首页 > 其他分享 >设置了msg放进model中了,前端页面却读取不出来?

设置了msg放进model中了,前端页面却读取不出来?

时间:2023-03-02 17:13:32浏览次数:35  
标签:redirect index 放进 return 读取 msg model

设置了msg放进model中了,前端页面却读取不出来?

index.html

<p style="color: red" 
   th:text="${msg}" 
   th:if="${not #strings.isEmpty(msg)}">
</p>

controller.java

 model.addAttribute("msg","用户名或者密码错误!");
 return "redirect:/index";
model.addAttribute("msg","用户名或者密码错误!");
System.out.println(model.getAttribute("msg"));
return "redirect:/index";

增加了System.out.println(model.getAttribute("msg"));,控制台中也输出了:用户名或者密码错误!

那这么看来msg是放进了model中的了。

再次核对index中这段代码没有错误的。

解决方法

取消重定向,将return "redirect:/index";改为return“index”,直接指向index.html。

标签:redirect,index,放进,return,读取,msg,model
From: https://www.cnblogs.com/LinQWblog/p/17172423.html

相关文章