Spring Boot前后端不分离,页面跳转以及通过th标签展示参数流程

Spring Boot前后端不分离,页面跳转以及通过th标签展示参数流程

后端页面跳转以及数据绑定操作,主要通过ModelModelMapModelAndView进行页面转发以及传参操作,具体示例代码如下所示:

@RequestMapping("/demo")
public String model(ModelMap modelMap,HttpServletRequest request)
{
    String patchCode = request.getParameter("patchCode");
    modelMap.addAttribute("patchCode",patchCode);// 数据绑定
    return prefix + "/checkDetail";// 跳转页面
}
@RequestMapping("/demo1")
public ModelAndView model1(ModelAndView modelAndView, HttpServletRequest request)
{
    String patchCode = request.getParameter("patchCode");
    modelAndView.setViewName(prefix + "/checkDetail");// 跳转页面
    modelAndView.addObject("patchCode",patchCode);// 数据绑定
    return modelAndView;
}
@RequestMapping("/demo2")
public String model2(Model model, HttpServletRequest request)
{
    String patchCode = request.getParameter("patchCode");
    model.addAttribute("patchCode",patchCode);// 数据绑定
    return prefix + "/checkDetail";// 跳转页面
}

前端通过thymeleaf标签获取值操作:

第一种取值方式:
<p id="patchCode"  th:text="${patchCode}"></p>
第二种取值方式:
<p  th:text="${#httpServletRequest.getAttribute('patchCode')}"></p>

如上所示,即可进行页面转发并实现传参展示操作!

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐