This commit is contained in:
click33 2021-10-19 20:37:36 +08:00
commit 82591e397f
3 changed files with 36 additions and 0 deletions

View File

@ -156,3 +156,31 @@ public class StpUserUtil {
再次调用 `StpUserUtil.login(10001)` 进行登录授权时token的名称将不再是 `satoken`,而是我们重写后的 `satoken-user`
### 7、不同体系不同配置
SaLoginModel 对象只是一个简单的配置对象, SaTokenConfig 对象的配置才是完整配置, 定义过程同上, 也很简单, 示例如下:
``` java
public class StpUserUtil {
// 使用匿名子类 重写`stpLogic对象`的一些方法
public static StpLogic stpLogic = new StpLogic(TYPE) {
// 重写配置获取方法
@Override
public SaTokenConfig getConfig() {
SaTokenConfig stpConfig = new SaTokenConfig();
stpConfig.setTimeout(-1);
stpConfig.setTokenPrefix("Bear");
stpConfig.setIsShare(true);
stpConfig.setIsConcurrent(true);
stpConfig.setTokenName("satoken");
stpConfig.setActivityTimeout(Duration.ofMinutes(30).getSeconds());
// 配置其他属性
return stpConfig;
}
};
// ...
}
```

View File

@ -35,6 +35,12 @@
<version>2.11.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.11.2</version>
<optional>true</optional>
</dependency>
</dependencies>

View File

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
@ -60,6 +61,7 @@ public class SaTokenDaoRedisJackson implements SaTokenDao {
field.setAccessible(true);
ObjectMapper objectMapper = (ObjectMapper) field.get(valueSerializer);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.registerModule(new JavaTimeModule());
this.objectMapper = objectMapper;
} catch (Exception e) {
System.err.println(e.getMessage());