页面返回异常
来源:12-1 -整体的需求回顾
慕斯卡7047622
2019-06-27
老师,
我的index page的登录跟退出是同时出现的
下面是我build.gradle的dependencies
dependencies {
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.2.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
compile 'net.java.dev.jna:jna:4.3.0'
compile 'mysql:mysql-connector-java:8.0.11'
runtime('com.h2database:h2:1.4.193')
testCompile 'org.springframework.boot:spring-boot-starter-test'
}
还有我的index和header.html
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head th:replace="fragments/header :: header">
</head>
<body>
<!-- Page content -->
<div class="container blog-content-container">
<div sec:authorize="isAuthenticated()">
<p>已有用户登录</p>
<p>登录的用户为: <span sec:authentication="name"></span></p>
<p>用户角色为: <span sec:authentication="principal.authorities"></span></p>
</div>
<div sec:authorize="isAnonymous()">
<p>未有用户登录</p>
</div>
</div><!-- /.container -->
<div th:replace="fragments/footer :: footer"></div>
</body>
</html>
======================================================
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"
th:fragment="header">
<head>
<meta charset="utf-8"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"></meta>
</head>
<body>
<nav class="navbar navbar-inverse bg-inverse navbar-toggleable-md">
<div class="container">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse"
data-target="#navbarsContainer">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="/" th:href="@{~/}">NewStarBlog</a>
<div class="collapse navbar-collapse" id="navbarsContainer">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" th:href="@{~/users}" >首页 <span class="sr-only">(current)</span></a>
</li>
</ul>
<!-- 登录判断 -->
<div sec:authorize="isAuthenticated()" class="row" >
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<span class="nav-link" sec:authentication="name"></span>
</li>
</ul>
<form action="/logout" th:action="@{/logout}" method="post">
<input class="btn btn-outline-success " type="submit" value="退出"></input>
</form>
</div>
<div sec:authorize="isAnonymous()">
<a href="/login" th:href="@{~/login}" class="btn btn-outline-success my-2 my-sm-0" type="submit">登录</a>
</div>
</div>
</div>
</nav>
</body>
</html>
我怀疑我的那个security是不是没配置正确?
写回答
1回答
-
老卫
2019-06-27
spring boot 版本是多少呢、建议跟课程的保持一致。
见我的手记022019-06-28
基于Spring Boot技术栈博客系统企业级前后端实战
毕设 Elasticsearch搜索+Thymeleaf模板+JPA+Security+BootStrap
1296 学习 · 738 问题
相似问题