段秦安 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日

悬赏问题

  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错