mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-09-21 02:57:56 +08:00
修复文档部分错误之处
This commit is contained in:
@@ -2,7 +2,7 @@ package com.pj.satoken;
|
|||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaCheckInterceptor;
|
import cn.dev33.satoken.annotation.SaCheckInterceptor;
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ import cn.dev33.satoken.annotation.SaCheckInterceptor;
|
|||||||
* sa-token代码方式进行配置
|
* sa-token代码方式进行配置
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class MySaTokenConfig extends WebMvcConfigurationSupport {
|
public class MySaTokenConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
// 获取配置Bean (以代码的方式配置sa-token)
|
// 获取配置Bean (以代码的方式配置sa-token)
|
||||||
// @Primary
|
// @Primary
|
||||||
|
@@ -5,7 +5,7 @@ import java.util.List;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ajax返回Json的封装
|
* ajax请求返回Json格式数据的封装
|
||||||
*/
|
*/
|
||||||
public class AjaxJson implements Serializable{
|
public class AjaxJson implements Serializable{
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ public class AjaxJson implements Serializable{
|
|||||||
public int code; // 状态码
|
public int code; // 状态码
|
||||||
public String msg; // 描述信息
|
public String msg; // 描述信息
|
||||||
public Object data; // 携带对象
|
public Object data; // 携带对象
|
||||||
public Long dataCount; // 数据总数
|
public Long dataCount; // 数据总数,用于分页
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回code
|
* 返回code
|
||||||
|
@@ -9,16 +9,14 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
|
|||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
|
|
||||||
import cn.dev33.satoken.exception.NotLoginException;
|
import cn.dev33.satoken.exception.NotLoginException;
|
||||||
import cn.dev33.satoken.exception.NotPermissionException;
|
import cn.dev33.satoken.exception.NotPermissionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加强版控制器
|
* 全局异常处理
|
||||||
*/
|
*/
|
||||||
@ControllerAdvice // 可指定包前缀,比如:(basePackages = "com.pj.admin")
|
@ControllerAdvice // 可指定包前缀,比如:(basePackages = "com.pj.admin")
|
||||||
public class TopController {
|
public class GlobalException {
|
||||||
|
|
||||||
// 在每个控制器之前触发的操作
|
// 在每个控制器之前触发的操作
|
||||||
@ModelAttribute
|
@ModelAttribute
|
||||||
@@ -28,7 +26,7 @@ public class TopController {
|
|||||||
|
|
||||||
// 全局异常拦截(拦截项目中的所有异常)
|
// 全局异常拦截(拦截项目中的所有异常)
|
||||||
@ExceptionHandler
|
@ExceptionHandler
|
||||||
public void handlerException(Exception e, HttpServletRequest request, HttpServletResponse response)
|
public AjaxJson handlerException(Exception e, HttpServletRequest request, HttpServletResponse response)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
// 打印堆栈,以供调试
|
// 打印堆栈,以供调试
|
||||||
@@ -44,10 +42,13 @@ public class TopController {
|
|||||||
} else { // 普通异常, 输出:500 + 异常信息
|
} else { // 普通异常, 输出:500 + 异常信息
|
||||||
aj = AjaxJson.getError(e.getMessage());
|
aj = AjaxJson.getError(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 返回给前端
|
||||||
|
return aj;
|
||||||
|
|
||||||
// 输出到客户端
|
// 输出到客户端
|
||||||
response.setContentType("application/json; charset=utf-8"); // http说明,我要返回JSON对象
|
// response.setContentType("application/json; charset=utf-8"); // http说明,我要返回JSON对象
|
||||||
response.getWriter().print(new ObjectMapper().writeValueAsString(aj));
|
// response.getWriter().print(new ObjectMapper().writeValueAsString(aj));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -102,8 +102,8 @@ public class TestController {
|
|||||||
|
|
||||||
@SaCheckLogin // 注解式鉴权:当前会话必须登录才能通过
|
@SaCheckLogin // 注解式鉴权:当前会话必须登录才能通过
|
||||||
@RequestMapping("getInfo")
|
@RequestMapping("getInfo")
|
||||||
public String getInfo() {
|
public AjaxJson getInfo() {
|
||||||
return "用户信息";
|
return AjaxJson.getSuccessData("用户信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
14
sa-token-doc/doc/index.css
Normal file
14
sa-token-doc/doc/index.css
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
.logo-box {position: absolute;left: 30px;top: 10px;cursor: pointer;color: #000;}
|
||||||
|
.logo-box img {width: 50px;height: 50px;vertical-align: middle;}
|
||||||
|
.logo-box .logo-text {display: inline-block;vertical-align: middle;font-size: 24px;font-weight: 400;}
|
||||||
|
#main {padding-bottom: 100px;}
|
||||||
|
#main h2 {font-size: 1.6rem;}
|
||||||
|
#main h3 {font-size: 1.25rem;}
|
||||||
|
@media screen and (max-width: 800px) {
|
||||||
|
.logo-box {display: none;}
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-box img{max-width: 600px; margin: 0.5em; box-shadow: 0 0 3px #999; transition: all 0.3s;}
|
||||||
|
|
||||||
|
.main-box img:hover{box-shadow: 0 0 10px #333; cursor: pointer;}
|
||||||
|
|
@@ -9,47 +9,8 @@
|
|||||||
<meta name="keywords" content="sa-token|sa-token框架|sa-token文档|sa-token在线文档|权限认证框架">
|
<meta name="keywords" content="sa-token|sa-token框架|sa-token文档|sa-token在线文档|权限认证框架">
|
||||||
<meta name="description" content="sa-token是一个JavaWeb权限认证框架,强大、简单、好用,登录验证、权限验证、自定义session会话、踢人下线、持久层扩展、无cookie模式、模拟他人账号、多账号体系、注解式鉴权、Spring集成...,零配置开箱即用,覆盖所有应用场景,你所需要的功能,这里都有">
|
<meta name="description" content="sa-token是一个JavaWeb权限认证框架,强大、简单、好用,登录验证、权限验证、自定义session会话、踢人下线、持久层扩展、无cookie模式、模拟他人账号、多账号体系、注解式鉴权、Spring集成...,零配置开箱即用,覆盖所有应用场景,你所需要的功能,这里都有">
|
||||||
<link rel="stylesheet" href="https://unpkg.com/docsify@4.11.3/lib/themes/vue.css">
|
<link rel="stylesheet" href="https://unpkg.com/docsify@4.11.3/lib/themes/vue.css">
|
||||||
|
<link rel="stylesheet" href="./index.css">
|
||||||
<link rel="shortcut icon" type="image/x-icon" href="logo.png">
|
<link rel="shortcut icon" type="image/x-icon" href="logo.png">
|
||||||
<style type="text/css">
|
|
||||||
.logo-box {
|
|
||||||
position: absolute;
|
|
||||||
left: 30px;
|
|
||||||
top: 10px;
|
|
||||||
cursor: pointer;
|
|
||||||
color: #000;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo-box img {
|
|
||||||
width: 50px;
|
|
||||||
height: 50px;
|
|
||||||
vertical-align: middle;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo-box .logo-text {
|
|
||||||
display: inline-block;
|
|
||||||
vertical-align: middle;
|
|
||||||
font-size: 24px;
|
|
||||||
font-weight: 400;
|
|
||||||
}
|
|
||||||
|
|
||||||
#main {
|
|
||||||
padding-bottom: 300px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#main h2 {
|
|
||||||
font-size: 1.6rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
#main h3 {
|
|
||||||
font-size: 1.25rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (max-width: 800px) {
|
|
||||||
.logo-box {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<a href="/">
|
<a href="/">
|
||||||
@@ -85,13 +46,28 @@
|
|||||||
// search: 'auto', // 搜索功能
|
// search: 'auto', // 搜索功能
|
||||||
alias: {
|
alias: {
|
||||||
'/.*/_sidebar.md': '/_sidebar.md'
|
'/.*/_sidebar.md': '/_sidebar.md'
|
||||||
}
|
},
|
||||||
|
plugins: [ // 自定义插件
|
||||||
|
function(hook, vm) {
|
||||||
|
// 解析之后执行
|
||||||
|
hook.afterEach(function(html) {
|
||||||
|
var url = 'https://github.com/click33/sa-token/tree/master/sa-token-doc/doc/' + vm.route.file;
|
||||||
|
var footer = [
|
||||||
|
'<br/><br/><br/><br/><br/><br/><br/><hr/>',
|
||||||
|
'<footer>',
|
||||||
|
' <span>发现错误?想参与编辑? <a href="' + url + '" target="_blank">在 GitHub 上编辑此页!</a> </span>',
|
||||||
|
'</footer>'
|
||||||
|
].join('');
|
||||||
|
return html + footer;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script src="https://unpkg.com/docsify@4.9.4/lib/docsify.min.js"></script>
|
<script src="https://unpkg.com/docsify@4.9.4/lib/docsify.min.js"></script>
|
||||||
<script src="https://unpkg.com/docsify-copy-code@2.1.0/dist/docsify-copy-code.min.js"></script>
|
<script src="https://unpkg.com/docsify-copy-code@2.1.0/dist/docsify-copy-code.min.js"></script>
|
||||||
<script src="https://unpkg.com/prismjs@1.19.0/components/prism-java.min.js"></script>
|
<script src="https://unpkg.com/prismjs@1.19.0/components/prism-java.min.js"></script>
|
||||||
<!-- <script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"></script> -->
|
<script src="https://cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
(function() {
|
(function() {
|
||||||
|
@@ -73,4 +73,4 @@ public class StpInterfaceImpl implements StpInterface {
|
|||||||
## 拦截全局异常
|
## 拦截全局异常
|
||||||
- 有同学要问,鉴权失败,抛出异常,然后呢?要把异常显示给用户看吗?
|
- 有同学要问,鉴权失败,抛出异常,然后呢?要把异常显示给用户看吗?
|
||||||
- 当然不能把异常抛给用户看,你可以创建一个全局异常拦截器,统一返回给前端的格式,例如以下示例:
|
- 当然不能把异常抛给用户看,你可以创建一个全局异常拦截器,统一返回给前端的格式,例如以下示例:
|
||||||
- 参考:[码云:TopController.java](https://gitee.com/sz6/sa-token/blob/master/sa-token-demo-springboot/src/main/java/com/pj/test/TopController.java)
|
- 参考:[码云:GlobalException.java](https://gitee.com/sz6/sa-token/blob/master/sa-token-demo-springboot/src/main/java/com/pj/test/GlobalException.java)
|
Reference in New Issue
Block a user