段秦安 2022-06-05 18:28 采纳率: 80%
浏览 144
已结题

springboot中前端$取值出错

springboot项目从数据库中取数据,html动态获取值,即数据库中有几条数据前端展示几条数据
但是html页面中$取值一致报红,即下html页面中${info_list}里面的 ”info_list“ 报红
项目可以运行,但是进不去index
报错如下:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/index.html]")] with root cause

日志上显示的就是前端页面的问题

Could not parse as expression: "@{${info.url}" (template: "index" - line 182, col 92)

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>

img

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,id
        from information
        where id = '1'
    </select>

数据库

img

  • 写回答

5条回答 默认 最新

  • 东芃9394 2022-06-05 22:41
    关注

    你好,是thymeleaf的循环语法使用错误:

    img

    thymeleaf正确的循环使用方法如下:

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 6月14日
  • 已采纳回答 6月6日
  • 创建了问题 6月5日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效