第一种方法,官方推荐使用。form 表单使用 th:action 属性, thymeleaf 会自动在 form 表单中生成 _csrf 隐藏域
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
...
<form class="form-signin" th:action="@{login}" action="login" method="post">
...
</form>
第二种方法,手动添加隐藏域。
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
第三种方法,加在请求头部分
<meta name="_csrf" th:content="${_csrf.token}"/>
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>