欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

thymeleaf添加点击事件 “th:onclick”传参使页面报错问题

程序员文章站 2022-07-02 19:43:14
thymeleaf th:onclick传参问题解决最近在开发过程中遇到springBoot使用thymeleaf模板引擎,添加点击事件会使页面报错的问题,下面分享一下自己的解决方法。一:可能是版本问题,在springboot2.0.0版本中使用下面写法会报错。
  • thymeleaf th:onclick传参问题解决

    最近在开发过程中遇到springBoot使用thymeleaf模板引擎,添加点击事件会使页面报错的问题,下面分享一下自己的解决方法。
    一:可能是版本问题,在springboot2.0.0版本中使用下面写法会报错。

    <li th:each="city:${cityList}">
          <a href="#" th:onclick="getSchoolList([[${city.id}]],[[${city.cityName}]]);">[[${city.cityName}]]</a>
    </li>
    

    在pom.xml中换成2.2.6版本或更高版本后使用正常。

    	<parent>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-parent</artifactId>
    		<version>2.2.6.RELEASE</version>
    		<relativePath/> <!-- lookup parent from repository -->
    	</parent>
    

    二:在不改变版本的情况下将写法换成这样,我的问题也解决了

    	<li th:each="city:${cityList}" th:onclick="|getSchoolList('${city.id}','${city.cityName}');|">
                <a href="#">[[${city.cityName}]]</a>
        </li>
    

    本文地址:https://blog.csdn.net/xl13003009535/article/details/107498985