mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-10-26 18:49:01 +08:00
升级优化一下 solon 相关集成 demo
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
<artifactId>sa-token-solon-plugin</artifactId>
|
||||
<version>${sa-token.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- sa-token整合redis (使用jdk默认序列化方式) -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.pj;
|
||||
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.session.SaSession;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.annotation.SolonMain;
|
||||
|
||||
@@ -16,5 +18,13 @@ public class SaTokenDemoApp {
|
||||
public static void main(String[] args) {
|
||||
Solon.start(SaTokenDemoApp.class, args);
|
||||
System.out.println("\n启动成功:Sa-Token配置如下:" + SaManager.getConfig());
|
||||
|
||||
SaSession session = StpUtil.getSessionByLoginId(10001);
|
||||
session.set("name", "zhang");
|
||||
session.set("user", new SysUser(10001, "张三"));
|
||||
|
||||
session = StpUtil.getSessionByLoginId(10001);
|
||||
System.out.println(session.get("name"));
|
||||
System.out.println(session.get("user"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.pj;
|
||||
|
||||
/**
|
||||
* @author click33
|
||||
* @since 2024/5/11
|
||||
*/
|
||||
public class SysUser {
|
||||
|
||||
public int id;
|
||||
|
||||
public String name;
|
||||
|
||||
public SysUser() {
|
||||
}
|
||||
public SysUser(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取
|
||||
*
|
||||
* @return id
|
||||
*/
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SysUser{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package com.pj.satoken;
|
||||
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.dao.SaTokenDao;
|
||||
import cn.dev33.satoken.dao.SaTokenDaoOfRedis;
|
||||
import cn.dev33.satoken.solon.integration.SaTokenInterceptor;
|
||||
import com.pj.util.AjaxJson;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
|
||||
import com.pj.util.AjaxJson;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
|
||||
@@ -59,9 +57,11 @@ public class SaTokenConfigure {
|
||||
;
|
||||
});
|
||||
}
|
||||
//如果需要 redis dao,加这段代表
|
||||
// @Bean
|
||||
// public SaTokenDao saTokenDaoInit(@Inject("${sa-token-dao.redis}") SaTokenDaoOfRedis saTokenDao) {
|
||||
// return saTokenDao;
|
||||
// }
|
||||
|
||||
//如果需要 redis dao,加这段代表
|
||||
@Bean
|
||||
public SaTokenDao saTokenDaoInit(@Inject("${sa-token-dao.redis}") SaTokenDaoOfRedis saTokenDao) {
|
||||
return saTokenDao;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user