码上敲享录 > thymeleaf > thymeleaf th:with 的使用

thymeleaf th:with 的使用

上一章章节目录下一章 2020-01-10已有6699人阅读 评论(0)

thymeleaf th:with的使用

两种简单的使用


第一种

前端代码:

<li>

模板类型:

<select name="status" th:with="templateType=${@template.getTemplateType()}">

<option value="">请选择</option>

<option th:each="t : ${templateType}" th:text="${t.templateTypeName}" th:value="${t.templateTypeId}"></option>

</select>

</li>


//后台services层

@Service("template")

public class TemplateServices {

   @Resource

   private TemplateDao templateDao;


   public List<DicTemplate> getTemplateType() {

       return templateDao.getTemplateType();

   }

}

要注意的是@后的服务名 要跟@service中一致(如template)



第二种:

前端代码:

<li>

模板类型:

<select name="status" th:with="templateType=${@templateServices.getTemplateType()}">

<option value="">请选择</option>

<option th:each="t : ${templateType}" th:text="${t.templateTypeName}" th:value="${t.templateTypeId}"></option>

</select>

</li>


//后台Controller层

Resource

private TemplateServices templateServices;

/**

* 查询模板列表

* @return

*/

@GetMapping("/getTemplateType")

@ResponseBody

public List<DicTemplate> getTemplateType() {

   List<DicTemplate> list =  templateServices.getTemplateType();

   return list;

}

//后台Service层

@Service

public class TemplateServices {

   @Resource

   private TemplateDao templateDao;


   public List<DicTemplate> getTemplateType() {

       return templateDao.getTemplateType();

   }

}


向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
1

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交