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

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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失