-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
381bf0f
commit e9b882c
Showing
10 changed files
with
139 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/xiaxinyu/myblog/interceptor/LoginInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.xiaxinyu.myblog.interceptor; | ||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
public class LoginInterceptor extends HandlerInterceptorAdapter { | ||
|
||
@Override | ||
public boolean preHandle(HttpServletRequest request, | ||
HttpServletResponse response, | ||
Object handler) throws Exception { | ||
if (request.getSession().getAttribute("user") == null) { | ||
response.sendRedirect("/admin"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
|
19 changes: 19 additions & 0 deletions
19
src/main/java/com/xiaxinyu/myblog/interceptor/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.xiaxinyu.myblog.interceptor; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
|
||
@Configuration | ||
public class WebConfig extends WebMvcConfigurerAdapter { | ||
|
||
@Override | ||
public void addInterceptors(InterceptorRegistry registry) { | ||
registry.addInterceptor(new LoginInterceptor()) | ||
.addPathPatterns("/admin/**") //想拦截的路径 | ||
.excludePathPatterns("/admin") //不想拦截的路径 | ||
.excludePathPatterns("/admin/login"); | ||
} | ||
} | ||
|
||
|
14 changes: 14 additions & 0 deletions
14
src/main/java/com/xiaxinyu/myblog/web/admin/BlogController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.xiaxinyu.myblog.web.admin; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
@RequestMapping("/admin") | ||
public class BlogController { | ||
@GetMapping("/blogs") | ||
public String showBlogs(){ | ||
return "admin/blogs"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> | ||
<head th:replace="admin/_fragments :: head(~{::title})"> | ||
<meta charset="UTF-8"> | ||
<!-- 设置移动端预览--> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>博客管理</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css"> | ||
<link rel="stylesheet" href="../../static/css/css/me.css"> | ||
<link rel="stylesheet" href="../../static/css/me.css"> | ||
</head> | ||
|
||
<body> | ||
|
||
<!--导航栏--> | ||
<nav class="ui inverted attached segment m-padded-tb-mini m-shadow-small"> | ||
<nav th:replace="admin/_fragments :: menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small"> | ||
<!-- attached 去除圆角--> | ||
<!-- inverted 颜色反转--> | ||
<div class="ui container"> | ||
|
@@ -137,7 +138,7 @@ <h2 class="ui teal header item">博客后台</h2> | |
<br> | ||
|
||
<!--底部footer--> | ||
<footer class="ui inverted attached segment m-padded-tb-massive"> | ||
<footer th:replace="admin/_fragments :: footer" class="ui inverted attached segment m-padded-tb-massive"> | ||
<div class="ui center aligned container"> | ||
<!-- center aligned使container内的内容居中 --> | ||
<div class="ui inverted divided stackable grid"> | ||
|
@@ -177,8 +178,11 @@ <h4 class="ui inverted header">My blog</h4> | |
|
||
</footer> | ||
|
||
<!--/*/<th:block th:replace="_fragments :: script">/*/--> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.js"></script> | ||
<!--/*/</th:block>/*/--> | ||
|
||
<script> | ||
$('.menu.toggle').click(function () { | ||
$(".m-item").toggleClass('m-mobile-hide'); | ||
|
Binary file added
BIN
+1.17 KB
target/classes/com/xiaxinyu/myblog/interceptor/LoginInterceptor.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> | ||
<head th:replace="admin/_fragments :: head(~{::title})"> | ||
<meta charset="UTF-8"> | ||
<!-- 设置移动端预览--> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>博客管理</title> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.css"> | ||
<link rel="stylesheet" href="../../static/css/css/me.css"> | ||
<link rel="stylesheet" href="../../static/css/me.css"> | ||
</head> | ||
|
||
<body> | ||
|
||
<!--导航栏--> | ||
<nav class="ui inverted attached segment m-padded-tb-mini m-shadow-small"> | ||
<nav th:replace="admin/_fragments :: menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow-small"> | ||
<!-- attached 去除圆角--> | ||
<!-- inverted 颜色反转--> | ||
<div class="ui container"> | ||
|
@@ -137,7 +138,7 @@ <h2 class="ui teal header item">博客后台</h2> | |
<br> | ||
|
||
<!--底部footer--> | ||
<footer class="ui inverted attached segment m-padded-tb-massive"> | ||
<footer th:replace="admin/_fragments :: footer" class="ui inverted attached segment m-padded-tb-massive"> | ||
<div class="ui center aligned container"> | ||
<!-- center aligned使container内的内容居中 --> | ||
<div class="ui inverted divided stackable grid"> | ||
|
@@ -177,8 +178,11 @@ <h4 class="ui inverted header">My blog</h4> | |
|
||
</footer> | ||
|
||
<!--/*/<th:block th:replace="_fragments :: script">/*/--> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/semantic.min.js"></script> | ||
<!--/*/</th:block>/*/--> | ||
|
||
<script> | ||
$('.menu.toggle').click(function () { | ||
$(".m-item").toggleClass('m-mobile-hide'); | ||
|