问题遇到的现象和发生背景
写了个网页想测试我的服务器能不能正常返回数据,使用了thymeleaf和springboot,我现在想在网页端以表格的形式显示我的数据,但是一直加载不出来
问题相关代码,请勿粘贴截图
第一部分,controller的定义
@Controller
@RequestMapping("/news")
public class NewsController {
private static Map<Integer,NewsAbs> newsListMap=null;
@Autowired
private NewsMapper newsMapper;
@RequestMapping("/list")
public String newsList(Model model){
//测试1
List<NewsAbs> newsAbsList=newsMapper.queryNewsAbsList();
newsListMap=new HashMap<Integer,NewsAbs>();
newsListMap.put(1,new NewsAbs(1,1,"aa"));
newsListMap.put(2,new NewsAbs(2,1,"bb"));
newsListMap.put(3,new NewsAbs(3,1,"cc"));
Collection<NewsAbs> newsAbsCollection=newsListMap.values();
model.addAttribute("newsAbsCollection",newsAbsCollection);
String title=newsListMap.get(1).getTitle();//可以得到“aa"
//最后测试
// ArrayList<NewsAbs> newsAbs=null;
// newsAbs.add(new NewsAbs(1,1,"aa"));
// newsAbs.add(new NewsAbs(2,1,"bb"));
// model.addAttribute("newsAbs",newsAbs);
return "newshtml/list";
}
第二部分list.html部分代码
<table class="table table-striped table-sm">
<thead>
<tr>
<th>id</th>
<th>title</th>
<th>great</th>
</tr>
</thead>
<tbody>
<tr th:each="new:${newsAbsCollection}">
<td th:text="${new.getId()}"></td>
<td th:text="${new.getTitle()}"></td>
<td th:text="${new.getGreat()}"></td>
</tr>
</tbody>
</table>
运行结果及报错内容
我的解答思路和尝试过的方法
开头确实有引入thymeleaf
```html
<!DOCTYPE html>
<!-- saved from url=(0052)http://getbootstrap.com/docs/4.0/examples/dashboard/ -->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
跟着狂神做的也可以成功显示,代码基本就是根据狂神的代码改的
###### 我想要达到的结果

