【问题标题】:Want to load the content dynamically when user click on some required contents thymeleaf想要在用户点击一些需要的内容时动态加载内容 thymeleaf
【发布时间】:2018-07-31 04:59:09
【问题描述】:

我对 thymeleaf 非常陌生,我一直致力于在 jsp 中运行良好的项目。现在我必须转向 Spring Boot,我面临一些问题。当用户请求映射 /staff 和 userClickManager 获得值 true 并且我想更改 index.html 同一文件中的内容时,我有我想要的这个控制器

@RequestMapping(value = "/", method = RequestMethod.GET)
private ModelAndView index() {

    ModelAndView model = new ModelAndView("index");
    model.addObject("title", "Home");
    model.addObject("userClickHome", true);
    return model;
}

@RequestMapping("/staff")
private static ModelAndView staff(){

    ModelAndView view = new ModelAndView("index");
    view.addObject("title", "Manager");
    view.addObject("userClickManagers", true);
    return view;
}

这是我的 旧 jsp 代码的原型,只希望它们在百里香中,谢谢

 <c:if test="${userClickHome==true}">
 <!-- load the manager.jsp file  -->
<%@include file="homeContent.jsp" %>>
 </c:if>


   <c:if test="${userClickManagers==true}">
 <!-- load the manager.jsp file  -->
 <%@include file="Manager.jsp" %>
 </c:if>

【问题讨论】:

  • stackoverflow.com/questions/22538900/…。而不是 addObject 使用 addAttribute.
  • 好吧,让我检查一下,谢谢
  • 它没有集成到同一个 index.html 文件中,而是在单击所需内容时打开 _blank 页面

标签: java jsp spring-mvc spring-boot thymeleaf


【解决方案1】:

你的 thymeleaf html 是什么样的?如果您阅读 set 属性,请在您的条件中使用 th:insert 或 th:replace。

【讨论】:

  • 我的问题很简单这是我的旧jsp代码>
  • @RequestMapping(value = "/") public ModelAndView home() { ModelAndView model = new ModelAndView("home"); model.addObject("title", "Home"); model.addObject("userClickHome", true);返回模型; } @RequestMapping(value = "/staff") public ModelAndView getManagerPage() { ModelAndView model = new ModelAndView("home"); model.addObject("title", "Manager"); model.addObject("userClickManagers", true);返回模型; }
  • 只想把它们放在百里香中
猜你喜欢
  • 2014-07-16
  • 1970-01-01
  • 2014-12-22
  • 2021-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-04
  • 2013-03-29
相关资源
最近更新 更多