jdbcTemplate 和 Thymeleaf模板引擎 查询 到模板赋值例子

二、  jdbcTemplate 和 Thymeleaf模板引擎  最简单输出例子

控制器代码

@GetMapping(value = "/test2")
    public String test2(Model model){

        sql = "SELECT * FROM boy ";
        List queryList = jdbcTemplate.queryForList(sql);

        model.addAttribute("boy", queryList);
        return  "aaa";

    }

html模板里的代码

<ul>
    <li th:each="a:${boy}">
        <span th:text="${a.id}"></span>
        <span th:text="${a.age}"></span>
        <span th:text="${a.cup_size}"></span>

    </li>
</ul>

注意,模板里的

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
不要漏了下面这句
xmlns:th="http://www.thymeleaf.org"
原文地址:https://www.cnblogs.com/kaka666/p/8322407.html