sec:authentication="name"一般用来获取用户名,但是我发现出现无效的问题,现提供两种方法。
法一:将spring版本降到2.0.9以下
法二:maven仓库里的版本旧了,thymeleaf-extras-springsecurity4
改为thymeleaf-extras-springsecurity5
即可,如下:
<!-- https://mvnrepository.com/artifact/org.thymeleaf.extras/thymeleaf-extras-springsecurity4 -->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<version>3.0.4.RELEASE</version>
</dependency>
如果使用的是org.thymeleaf
,也要改为5
如果是starter的thymeleaf不需要修改:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>