springboot项目从数据库中取数据,html动态获取值,但是html页面中$取值一致报红,即下html页面中${info_list}里面的info_list
这种问题处在什么地方?
html页面
<li th:each="info = ${info_list}">
<div >< th:src="@{${info.url}" alt="emptyimg" /></div>
<div>
<h6 th:text="${info.title}"></h6>
<p th:text="${info.profile}"></p>
<span " th:text="${info.location}"> </span>
</li>
controller代码
@RequestMapping("/toindex")
public String toIndex(Model model) {
List<Information> info_list = informationDao.queryInfo();
model.addAttribute("info_list", info_list);
return "index";
}
dao代码
@Mapper
public interface InformationDao {
List<Information> queryInfo();
}
mapper.xml
<select id="queryInfo" resultMap="InformationMap">
select
title,profile,location
from information
where id = 'index'
</select>
数据库
你的改成这样
<li th:each="info:${info_list}">
<div >< th:src="@{${info.url}" alt="emptyimg" /></div>
<div>
<h6 th:text="${info.title}"></h6>
<p th:text="${info.profile}"></p>
<span " th:text="${info.location}"> </span>
</li>
遍历列表这样写
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>循环遍历Array数组</title>
</head>
<body>
<h1>循环遍历Array数组(使用方法和list一样)</h1>
<div th:each="user:${users}">
<span th:text="${userStat.index}"></span>
<span th:text="${userStat.count}"></span>
<span th:text="${user.id}"></span>
<span th:text="${user.name}"></span>
<span th:text="${user.phone}"></span>
<span th:text="${user.address}"></span>
</div>
</body>
</html>