springBoot整合thymeleaf时th:onclick事件

今天按照

《JavaEE开发的颠覆者: Spring Boot实战》

学习spring boot的时候在编写7_2时thymeleaf传参的时候发生500错误,通过查找各方面资料,发现书上的springboot版本(1.3.0)和我用的版本(2.1.7)不一样引起的

以下处理方法:

1.   将springboot版本改成2.0.5

2.   3.x版本的thymeleaf为了防止注入攻击,升级了安全机制

解决

修改前

<button th:onclick="'javascript:getName(this,\''+${person.name}+'\');'" type="button">获得名字</button>

修改后

<button th:data-name="${person.name}" onclick="getName(this,this.getAttribute('data-name'))" type="button">获得名字</button>

posted @ 2019-08-15 14:13  薄情的树先生  阅读(7661)  评论(0编辑  收藏  举报