@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>shiro</artifactId>
|
||||
<groupId>com.bjmashibing.shiro</groupId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>shiro-serialization</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.esotericsoftware/kryo -->
|
||||
<dependency>
|
||||
<groupId>com.esotericsoftware</groupId>
|
||||
<artifactId>kryo</artifactId>
|
||||
<version>5.0.0-RC5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,34 @@
|
||||
package com.bjmashibing.config;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* <p>redis配置</p>
|
||||
*
|
||||
* @author sunzhiqiang23
|
||||
* @date 2020-04-27 19:47
|
||||
*/
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
/**
|
||||
* shiro redis缓存使用的模板
|
||||
* 实例化 RedisTemplate 对象
|
||||
* @return
|
||||
*/
|
||||
@Bean("shiroRedisTemplate")
|
||||
public RedisTemplate shiroRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
|
||||
RedisTemplate redisTemplate = new RedisTemplate();
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.bjmashibing.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 用户信息表
|
||||
* </p>
|
||||
*
|
||||
* @author 孙志强
|
||||
* @since 2020-04-13
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class User extends UserSuper implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 用户主键
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 登录账户
|
||||
*/
|
||||
private String username;
|
||||
|
||||
public static String realName ="static";
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.bjmashibing.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
|
||||
/**
|
||||
* <p></p>
|
||||
*
|
||||
* @author sunzhiqiang23
|
||||
* @date 2020-06-16 20:23
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class User1 extends UserSuper implements Externalizable {
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
||||
/**
|
||||
* 用户主键
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 登录账户
|
||||
*/
|
||||
private String username;
|
||||
|
||||
public static String realName ="static";
|
||||
|
||||
@Override
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
out.writeObject(id);
|
||||
out.writeObject(username);
|
||||
out.writeObject(realName);
|
||||
out.writeObject(super.getSuperName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
|
||||
id = (Long) in.readObject();
|
||||
username = (String) in.readObject();
|
||||
realName = (String) in.readObject();
|
||||
String superName = (String) in.readObject();
|
||||
setSuperName(superName);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.bjmashibing.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p></p>
|
||||
*
|
||||
* @author sunzhiqiang23
|
||||
* @date 2020-06-16 21:08
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
public class UserSuper {
|
||||
|
||||
private String superName;
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.bjmashibing.util;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.DeserializationConfig;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Bean 类型转换 - Jackson 版实现
|
||||
*
|
||||
* @author sunzhiqiang
|
||||
* @version 1.0
|
||||
* @date 2017/4/14
|
||||
*/
|
||||
@Slf4j
|
||||
public class JacksonBeanConvertor {
|
||||
private static ObjectMapper objectMapper;
|
||||
static {
|
||||
objectMapper = new ObjectMapper();
|
||||
//指定时间格式
|
||||
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
||||
//检测所有字段,包括私有的
|
||||
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
|
||||
//序列化时忽略空属性
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
//反序列化时忽略不一致成员变量
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
}
|
||||
|
||||
public <T> T convert(Object fromValue, Class<T> toValueType) {
|
||||
return objectMapper.convertValue(fromValue, toValueType);
|
||||
}
|
||||
|
||||
public <T> T convert(Object fromValue, Type typeOfT) {
|
||||
JavaType toValueType = objectMapper.getTypeFactory().constructType(typeOfT);
|
||||
return objectMapper.convertValue(fromValue, toValueType);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.bjmashibing.util;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* <p>计算方法执行时间工具类-粗略测试批量导入导出考勤报表用</p>
|
||||
*
|
||||
* @author sunzhiqiang23
|
||||
* @date 2019/12/25 11:22
|
||||
*/
|
||||
@Slf4j
|
||||
public class TimeTool {
|
||||
private static final SimpleDateFormat FMT = new SimpleDateFormat("HH::mm:ss.SSS");
|
||||
|
||||
public interface Task {
|
||||
void execute();
|
||||
}
|
||||
|
||||
public static void check(String title, Task task) {
|
||||
if (task == null) {
|
||||
return;
|
||||
}
|
||||
title = (title == null) ? "" : ("【" + title + "】");
|
||||
System.out.println(title);
|
||||
|
||||
long begin = System.currentTimeMillis();
|
||||
task.execute();
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
|
||||
System.out.println("结束:" + FMT.format(new Date()));
|
||||
double delta = (end - begin) / 1000.0;
|
||||
System.out.println("耗时:" + delta + "秒");
|
||||
System.out.println("-------------------------");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
# Tomcat
|
||||
server:
|
||||
tomcat:
|
||||
uri-encoding: UTF-8
|
||||
max-threads: 1000
|
||||
min-spare-threads: 30
|
||||
port: 8002
|
||||
spring:
|
||||
mvc:
|
||||
static-path-pattern: /static/**
|
||||
freemarker:
|
||||
suffix: .html
|
||||
request-context-attribute: request
|
||||
jackson:
|
||||
time-zone: GMT+8
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
# 集群配置
|
||||
redis:
|
||||
expireSeconds: 60
|
||||
timeout: 5000ms #redis操作的超时时间
|
||||
database: 0
|
||||
host: 192.168.254.201
|
||||
port: 6379
|
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!-- Logback configuration. See http://logback.qos.ch/manual/index.html -->
|
||||
<configuration scan="true" scanPeriod="10 seconds">
|
||||
<include resource="org/springframework/boot/logging/logback/base.xml"/>
|
||||
|
||||
<logger name="com.bjmashibing.shiro" level="debug"/>
|
||||
</configuration>
|
@ -0,0 +1,14 @@
|
||||
package com.bjmashibing;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
public class ApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.bjmashibing.deepcopy;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* <p></p>
|
||||
*
|
||||
* @author sunzhiqiang23
|
||||
* @date 2020-06-16 22:12
|
||||
*/
|
||||
public class DeepCopyBeanUtils {
|
||||
public static <T extends Serializable> T clone(T obj) {
|
||||
// 拷贝产生的对象
|
||||
T clonedObj = null;
|
||||
try {
|
||||
// 读取对象字节数据
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(obj);
|
||||
oos.close();
|
||||
// 分配内存空间,写入原始对象,生成新对象
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
//返回新对象,并做类型转换
|
||||
clonedObj = (T)ois.readObject();
|
||||
ois.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return clonedObj;
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package com.bjmashibing.jdk;
|
||||
|
||||
import com.bjmashibing.entity.User;
|
||||
import com.bjmashibing.entity.User1;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* <p></p>
|
||||
*
|
||||
* @author sunzhiqiang23
|
||||
* @date 2020-06-15 22:08
|
||||
*/
|
||||
public class ExternalizableTest {
|
||||
/**
|
||||
* 测试序列化
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testSeri()throws Exception{
|
||||
//初始化对象
|
||||
User1 user = new User1();
|
||||
user.setId(1L);
|
||||
user.setUsername("序列化");
|
||||
//序列化对象到文件中
|
||||
File file = new File("result1.obj");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
|
||||
oos.writeObject(user);
|
||||
oos.close();
|
||||
}
|
||||
/**
|
||||
* 测试反序列化
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testDesSeri()throws Exception{
|
||||
File file = new File("result1.obj");
|
||||
//反序列化
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
|
||||
User1 newUser = (User1) ois.readObject();
|
||||
System.out.println(newUser.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试static修饰的属性能否被序列化
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testStaticSeri()throws Exception{
|
||||
//初始化对象
|
||||
User1 user = new User1();
|
||||
user.setId(1L);
|
||||
user.setUsername("序列化");
|
||||
System.out.println(user);
|
||||
//序列化对象到文件中
|
||||
File file = new File("result1.obj");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
|
||||
oos.writeObject(user);
|
||||
oos.close();
|
||||
//反序列化
|
||||
User1.realName = "update";
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
|
||||
User1 newUser = (User1)ois.readObject();
|
||||
System.out.println(newUser.realName);
|
||||
}
|
||||
/**
|
||||
* 测试static修饰的属性能否被序列化
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testExtendsSeri()throws Exception{
|
||||
//初始化对象
|
||||
User1 user = new User1();
|
||||
user.setId(1L);
|
||||
user.setUsername("序列化");
|
||||
user.setSuperName("父亲");
|
||||
|
||||
System.out.println(user);
|
||||
//序列化对象到文件中
|
||||
File file = new File("result.obj");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
|
||||
oos.writeObject(user);
|
||||
oos.close();
|
||||
//反序列化
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
|
||||
User1 newUser = (User1)ois.readObject();
|
||||
System.out.println(newUser.getSuperName());
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package com.bjmashibing.jdk;
|
||||
|
||||
import com.bjmashibing.entity.User;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* <p></p>
|
||||
*
|
||||
* @author sunzhiqiang23
|
||||
* @date 2020-06-15 22:08
|
||||
*/
|
||||
public class SerializableTest {
|
||||
/**
|
||||
* 测试序列化
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testSeri()throws Exception{
|
||||
//初始化对象
|
||||
User user = new User();
|
||||
user.setId(1L);
|
||||
user.setUsername("序列化");
|
||||
//序列化对象到文件中
|
||||
File file = new File("result.obj");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
|
||||
oos.writeObject(user);
|
||||
oos.close();
|
||||
}
|
||||
/**
|
||||
* 测试反序列化
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testDesSeri()throws Exception{
|
||||
File file = new File("result.obj");
|
||||
//反序列化
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
|
||||
User newUser = (User)ois.readObject();
|
||||
System.out.println(newUser.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试static修饰的属性能否被序列化
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testStaticSeri()throws Exception{
|
||||
//初始化对象
|
||||
User user = new User();
|
||||
user.setId(1L);
|
||||
user.setUsername("序列化");
|
||||
|
||||
System.out.println(user);
|
||||
//序列化对象到文件中
|
||||
File file = new File("result.obj");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
|
||||
oos.writeObject(user);
|
||||
oos.close();
|
||||
//反序列化
|
||||
User.realName = "update";
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
|
||||
User newUser = (User)ois.readObject();
|
||||
System.out.println(newUser.realName);
|
||||
}
|
||||
/**
|
||||
* 测试static修饰的属性能否被序列化
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testExtendsSeri()throws Exception{
|
||||
//初始化对象
|
||||
User user = new User();
|
||||
user.setId(1L);
|
||||
user.setUsername("序列化");
|
||||
user.setSuperName("父亲");
|
||||
|
||||
System.out.println(user);
|
||||
//序列化对象到文件中
|
||||
File file = new File("result.obj");
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
|
||||
oos.writeObject(user);
|
||||
oos.close();
|
||||
//反序列化
|
||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
|
||||
User newUser = (User)ois.readObject();
|
||||
System.out.println(newUser.getSuperName());
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package com.bjmashibing.performance;
|
||||
|
||||
import com.bjmashibing.entity.User;
|
||||
import com.bjmashibing.entity.UserSuper;
|
||||
import com.bjmashibing.util.KryoUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* <p></p>
|
||||
*
|
||||
* @author sunzhiqiang23
|
||||
* @date 2020-06-17 21:08
|
||||
*/
|
||||
public class PerformanceTest {
|
||||
|
||||
@Test
|
||||
public void testKryo() {
|
||||
UserSuper user = new UserSuper();
|
||||
user.setSuperName("测试");
|
||||
|
||||
byte[] bytes = KryoUtil.writeToByteArray(user);
|
||||
UserSuper user1 = KryoUtil.readObjectFromByteArray(bytes, UserSuper.class);
|
||||
System.out.println(user1);
|
||||
|
||||
}
|
||||
|
||||
}
|
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 197 KiB |
After Width: | Height: | Size: 123 KiB |
After Width: | Height: | Size: 200 KiB |
After Width: | Height: | Size: 100 KiB |
After Width: | Height: | Size: 292 KiB |
After Width: | Height: | Size: 440 KiB |
After Width: | Height: | Size: 94 KiB |