update at 2020-12-09 17:27:50 by ehlxr
parent
e764f36b1f
commit
a552a39e4d
82
pom.xml
82
pom.xml
|
@ -11,6 +11,11 @@
|
|||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<!--目标编译的 Java 版本可以通过以下属性指定,不用配置 maven-compiler-plugin 插件-->
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
|
||||
<spring.version>5.2.6.RELEASE</spring.version>
|
||||
<servlet.version>2.5</servlet.version>
|
||||
<mybatis.version>3.2.7</mybatis.version>
|
||||
|
@ -286,20 +291,35 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
|
||||
<dependency>
|
||||
<groupId>com.rabbitmq</groupId>
|
||||
<artifactId>amqp-client</artifactId>
|
||||
<version>4.8.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.hbase/hbase-client -->
|
||||
<dependency>
|
||||
<groupId>org.apache.hbase</groupId>
|
||||
<artifactId>hbase-client</artifactId>
|
||||
<version>1.3.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>2.10.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.10.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.14.7</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -325,15 +345,15 @@
|
|||
</plugin>
|
||||
|
||||
<!-- 指定JDK编译版本 -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>${jdk.verion}</source>
|
||||
<target>${jdk.verion}</target>
|
||||
<encoding>${file_encoding}</encoding>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!--<plugin>-->
|
||||
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <source>${jdk.verion}</source>-->
|
||||
<!-- <target>${jdk.verion}</target>-->
|
||||
<!-- <encoding>${file_encoding}</encoding>-->
|
||||
<!-- </configuration>-->
|
||||
<!--</plugin>-->
|
||||
|
||||
<!-- jetty 服务器; Maven build... -> jetty:run -->
|
||||
<plugin>
|
||||
|
@ -423,26 +443,26 @@
|
|||
<jvmTarget>1.8</jvmTarget>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>testCompile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!--<plugin>-->
|
||||
<!-- <groupId>org.apache.maven.plugins</groupId>-->
|
||||
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
|
||||
<!-- <executions>-->
|
||||
<!-- <execution>-->
|
||||
<!-- <id>compile</id>-->
|
||||
<!-- <phase>compile</phase>-->
|
||||
<!-- <goals>-->
|
||||
<!-- <goal>compile</goal>-->
|
||||
<!-- </goals>-->
|
||||
<!-- </execution>-->
|
||||
<!-- <execution>-->
|
||||
<!-- <id>testCompile</id>-->
|
||||
<!-- <phase>test-compile</phase>-->
|
||||
<!-- <goals>-->
|
||||
<!-- <goal>testCompile</goal>-->
|
||||
<!-- </goals>-->
|
||||
<!-- </execution>-->
|
||||
<!-- </executions>-->
|
||||
<!--</plugin>-->
|
||||
</plugins>
|
||||
<defaultGoal>compile</defaultGoal>
|
||||
</build>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/8/3.
|
||||
* Created by ehlxr on 2017/8/3.
|
||||
*/
|
||||
public class CharToHex {
|
||||
private final static char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||
|
|
|
@ -3,7 +3,7 @@ package me.ehlxr;
|
|||
import java.io.*;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/11/17.
|
||||
* Created by ehlxr on 2017/11/17.
|
||||
* <p>
|
||||
* 递归扫描 Java 文件,添加 CopyRight 信息,已有跳过
|
||||
*/
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.security.spec.PKCS8EncodedKeySpec;
|
|||
import java.security.spec.X509EncodedKeySpec;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/8/1.
|
||||
* Created by ehlxr on 2017/8/1.
|
||||
*/
|
||||
public class DemoECDSA {
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/6/20.
|
||||
* Created by ehlxr on 2017/6/20.
|
||||
*/
|
||||
public class LambdaTest {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2016/11/8.
|
||||
* Created by ehlxr on 2016/11/8.
|
||||
*/
|
||||
public class MD2Json {
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2018/2/13.
|
||||
* Created by ehlxr on 2018/2/13.
|
||||
*/
|
||||
public class PrintMatrixClockWisely {
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @date 2018/8/21
|
||||
*/
|
||||
public class ReferenceCountingGC {
|
||||
|
|
|
@ -3,7 +3,7 @@ package me.ehlxr;
|
|||
import java.io.*;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @date 2017/3/27
|
||||
*/
|
||||
public class Rename {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2018/1/16.
|
||||
* Created by ehlxr on 2018/1/16.
|
||||
* 可变参数
|
||||
*/
|
||||
public class VarArgsTest {
|
||||
|
|
|
@ -13,7 +13,7 @@ import javax.jms.TextMessage;
|
|||
|
||||
/**
|
||||
* 消息的消费者(接受者)
|
||||
* Created by lixiangrong on 2016-07-11
|
||||
* Created by ehlxr on 2016-07-11
|
||||
*/
|
||||
public class JMSConsumer {
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import javax.jms.TextMessage;
|
|||
|
||||
/**
|
||||
* 消息的生产者(发送者)
|
||||
* Created by lixiangrong on 2016-07-11.
|
||||
* Created by ehlxr on 2016-07-11.
|
||||
*/
|
||||
public class JMSProducer {
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
*
|
||||
*/
|
||||
@Target(ElementType.PACKAGE)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
*
|
||||
*/
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
*
|
||||
*/
|
||||
@PkgAnnotation
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.util.concurrent.Future;
|
|||
import java.util.concurrent.FutureTask;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/4/11.
|
||||
* Created by ehlxr on 2017/4/11.
|
||||
*/
|
||||
public class TestFutureCahe<K, V> {
|
||||
private final ConcurrentHashMap<K, Future<V>> cacheMap = new ConcurrentHashMap<K, Future<V>>();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2016/12/23.
|
||||
* Created by ehlxr on 2016/12/23.
|
||||
*/
|
||||
public class dfd {
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2020/2/26.
|
||||
*/
|
||||
public class Main {
|
||||
|
|
|
@ -23,7 +23,7 @@ public class PackView extends JFrame {
|
|||
private JButton jb1 = new JButton();
|
||||
private JButton jb2 = new JButton();
|
||||
private String inputPath = "D:\\wins-dsp";
|
||||
private String outputPath = "C:\\Users\\lixiangrong\\Desktop";
|
||||
private String outputPath = "C:\\Users\\ehlxr\\Desktop";
|
||||
private JLabel jl0 = new JLabel();
|
||||
private JButton cancel = new JButton("退出");
|
||||
private JTextPane jText1 = new JTextPane();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr.powermock;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/11/3.
|
||||
* Created by ehlxr on 2017/11/3.
|
||||
*/
|
||||
public class ClassDependency {
|
||||
public static boolean isExist() {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package me.ehlxr.powermock;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/11/3.
|
||||
* Created by ehlxr on 2017/11/3.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/7/21.
|
||||
* Created by ehlxr on 2017/7/21.
|
||||
*/
|
||||
public class ClassUnderTest {
|
||||
private String f1 = "test";
|
||||
|
|
|
@ -14,7 +14,7 @@ import static org.mockito.ArgumentMatchers.anyString;
|
|||
import static org.powermock.api.mockito.PowerMockito.*;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/7/21.
|
||||
* Created by ehlxr on 2017/7/21.
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
public class TestClassUnderTest {
|
||||
|
|
|
@ -3,7 +3,7 @@ package me.ehlxr.proxy;
|
|||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-06-28.
|
||||
*/
|
||||
public class Bird implements Flyable {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr.proxy;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-06-28.
|
||||
*/
|
||||
public interface Flyable {
|
||||
|
|
|
@ -3,7 +3,7 @@ package me.ehlxr.proxy;
|
|||
import java.lang.reflect.Proxy;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-06-28.
|
||||
*/
|
||||
public class Main {
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-06-28.
|
||||
*/
|
||||
public class MyInvocationHandler implements InvocationHandler {
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.io.IOException;
|
|||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
public class ConnectionUtil {
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.concurrent.TimeoutException;
|
|||
/**
|
||||
* 发送消息到交换机并且要指定路由 key ,消费者将队列绑定到交换机时需要指定路由 key
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
public class Receiver1 {
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.concurrent.TimeoutException;
|
|||
/**
|
||||
* 发送消息到交换机并且要指定路由 key ,消费者将队列绑定到交换机时需要指定路由 key
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
public class Receiver2 {
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.concurrent.TimeoutException;
|
|||
/**
|
||||
* 发送消息到交换机并且要指定路由 key ,消费者将队列绑定到交换机时需要指定路由 key
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
public class Sender {
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.concurrent.TimeoutException;
|
|||
/**
|
||||
* 简单模式:一个生产者,一个消费者
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
public class Receiver {
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.concurrent.TimeoutException;
|
|||
/**
|
||||
* 简单模式:一个生产者,一个消费者
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.concurrent.TimeoutException;
|
|||
/**
|
||||
* topic 模式:将路由键和某模式进行匹配,此时队列需要绑定在一个模式上,“#” 匹配一个词或多个词,“*” 只匹配一个词。
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.concurrent.TimeoutException;
|
|||
/**
|
||||
* topic 模式:将路由键和某模式进行匹配,此时队列需要绑定在一个模式上,“#” 匹配一个词或多个词,“*” 只匹配一个词。
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
public class Receiver2 {
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.concurrent.TimeoutException;
|
|||
/**
|
||||
* topic 模式:将路由键和某模式进行匹配,此时队列需要绑定在一个模式上,“#” 匹配一个词或多个词,“*” 只匹配一个词。
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
public class Sender {
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.concurrent.TimeoutException;
|
|||
/**
|
||||
* work 模式:一个生产者,多个消费者,每个消费者获取到的消息唯一
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
public class Receiver1 {
|
||||
|
|
|
@ -11,7 +11,7 @@ import java.util.concurrent.TimeoutException;
|
|||
/**
|
||||
* work 模式:一个生产者,多个消费者,每个消费者获取到的消息唯一
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
public class Receiver2 {
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.concurrent.TimeoutException;
|
|||
/**
|
||||
* work 模式:一个生产者,多个消费者,每个消费者获取到的消息唯一
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-01-22.
|
||||
*/
|
||||
public class Sender {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr.rate;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-07-18.
|
||||
*/
|
||||
public class Main {
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
/**
|
||||
* 按比例控制流量
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @since 2019-07-19.
|
||||
*/
|
||||
public class RateBarrier {
|
||||
|
|
|
@ -4,7 +4,7 @@ import rx.Observable;
|
|||
import rx.Subscriber;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2018/1/16.
|
||||
* Created by ehlxr on 2018/1/16.
|
||||
*/
|
||||
public class HelloRxJava {
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import io.reactivex.Flowable;
|
|||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2018/1/16.
|
||||
* Created by ehlxr on 2018/1/16.
|
||||
*/
|
||||
public class SchedulerTest {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
|
|
|
@ -5,7 +5,7 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @date 2018/1/16
|
||||
* <p>
|
||||
* Future<V> 是一个泛型接口,如果一个可运行的函数(实现 Callable 或 Runable 的类)在一个线程中运行,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr.reactive;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2018/1/16.
|
||||
* Created by ehlxr on 2018/1/16.
|
||||
*/
|
||||
public class TestLambda {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import rx.Observable;
|
|||
import rx.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2018/1/16.
|
||||
* Created by ehlxr on 2018/1/16.
|
||||
*/
|
||||
public class TestRx {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import rx.Subscriber;
|
|||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2018/1/16.
|
||||
* Created by ehlxr on 2018/1/16.
|
||||
* 链式函数式处理
|
||||
*/
|
||||
public class TestRx01 {
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.Arrays;
|
|||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2018/1/16.
|
||||
* Created by ehlxr on 2018/1/16.
|
||||
*/
|
||||
public class TimeConsumingService implements Callable<String> {
|
||||
|
||||
|
|
|
@ -381,7 +381,7 @@ public class JedisUtil {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JedisUtil.set("lxr", "hah lixiangrong");
|
||||
JedisUtil.set("lxr", "hah ehlxr");
|
||||
System.out.println(JedisUtil.getStr("lxr"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import com.jcraft.jsch.SftpException;
|
|||
/**
|
||||
* SFTP工具类
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
*
|
||||
*/
|
||||
public class SFTPUtil {
|
||||
|
|
|
@ -13,7 +13,7 @@ public class ExecBaics50Log {
|
|||
public static void main(String[] args) throws Exception {
|
||||
StringBuffer sb = new StringBuffer("");
|
||||
|
||||
FileReader reader = new FileReader("C:\\Users\\lixiangrong\\Desktop\\minisite\\20160606\\3\\2016-06-06(3、4、5).txt");
|
||||
FileReader reader = new FileReader("C:\\Users\\ehlxr\\Desktop\\minisite\\20160606\\3\\2016-06-06(3、4、5).txt");
|
||||
BufferedReader br = new BufferedReader(reader);
|
||||
String str = null;
|
||||
while ((str = br.readLine()) != null) {
|
||||
|
|
|
@ -3,7 +3,7 @@ package me.ehlxr.test;
|
|||
import me.ehlxr.redis.JedisUtil;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2016/6/14.
|
||||
* Created by ehlxr on 2016/6/14.
|
||||
*/
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr.test;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2016/12/15.
|
||||
* Created by ehlxr on 2016/12/15.
|
||||
*/
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.Calendar;
|
|||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2016/8/11.
|
||||
* Created by ehlxr on 2016/8/11.
|
||||
*/
|
||||
public class TestCalendar {
|
||||
|
||||
|
|
|
@ -168,19 +168,19 @@ public class TestCode {
|
|||
// System.out.println(Integer.valueOf("11", 2));
|
||||
|
||||
|
||||
// System.out.println(AESTool.encrypt("lixiangrong"));
|
||||
// System.out.println(AESTool.decrypt(AESEncrypter.encrypt("lixiangrong")));
|
||||
// System.out.println(AESTool.encrypt("ehlxr"));
|
||||
// System.out.println(AESTool.decrypt(AESEncrypter.encrypt("ehlxr")));
|
||||
|
||||
// System.out.println(AESTool.encrypt("liixangrong","adjdjfjfjfjdkdkd"));
|
||||
// System.out.println(AESTool.decrypt("bfb0c038342ffead45511879853279bf","adjdjfjfjfjdkdkd"));
|
||||
// System.out.println(Base64.encodeToString(AESTool.encrypt("fa4d7d90618dcba5fa1d969cffc04def","002020202").getBytes(), false));
|
||||
|
||||
// byte[] bytes = "lixiangrong".getBytes();
|
||||
// byte[] bytes = "ehlxr".getBytes();
|
||||
// for (int i = 0; i < bytes.length; i++) {
|
||||
// System.out.println(bytes[i]);
|
||||
// }
|
||||
|
||||
// System.out.println(Base64.encodeToString("lixiangrong".getBytes(), false));
|
||||
// System.out.println(Base64.encodeToString("ehlxr".getBytes(), false));
|
||||
|
||||
// double lon1 = 109.0145193759;
|
||||
// double lat1 = 34.236080797698;
|
||||
|
|
|
@ -3,7 +3,7 @@ package me.ehlxr.test;
|
|||
import org.apache.commons.codec.binary.Hex;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2016/9/12.
|
||||
* Created by ehlxr on 2016/9/12.
|
||||
*/
|
||||
public class TestDecodeHex {
|
||||
// 十六进制转字符串
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr.test;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2016/8/31.
|
||||
* Created by ehlxr on 2016/8/31.
|
||||
*/
|
||||
public class TestException {
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.io.IOException;
|
|||
|
||||
public class TestFile {
|
||||
public static void main(String[] args) {
|
||||
File file = new File("C:\\Users\\lixiangrong\\Desktop\\20160628\\161845");
|
||||
File file = new File("C:\\Users\\ehlxr\\Desktop\\20160628\\161845");
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ import java.util.Map;
|
|||
public class TestReadFile {
|
||||
|
||||
public static void readFile() {
|
||||
File file = new File("C:/Users/lixiangrong/Desktop/IPB.txt");
|
||||
File file = new File("C:/Users/ehlxr/Desktop/IPB.txt");
|
||||
BufferedReader reader = null;
|
||||
Map<String, Object> resultMap = null;
|
||||
List<Long> startList = null;
|
||||
|
@ -52,7 +52,7 @@ public class TestReadFile {
|
|||
}
|
||||
|
||||
public static void readFile1() {
|
||||
File file = new File("C:\\Users\\lixiangrong\\Desktop\\白名单\\IMEI\\000000_0");
|
||||
File file = new File("C:\\Users\\ehlxr\\Desktop\\白名单\\IMEI\\000000_0");
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(file));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr.test;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/4/14.
|
||||
* Created by ehlxr on 2017/4/14.
|
||||
*/
|
||||
public class TestReference {
|
||||
public static void main(String[] args) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import java.util.zip.CRC32;
|
|||
/**
|
||||
* IntelliJ IDEA 14.0.1 注册机
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
*
|
||||
*/
|
||||
public class keygen {
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
* @date 2016/12/22
|
||||
*/
|
||||
//@SuppressWarnings({"AlibabaRemoveCommentedCode", "Convert2Lambda", "UnnecessaryLocalVariable"})
|
||||
|
|
|
@ -5,7 +5,7 @@ package me.ehlxr.token;
|
|||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2018/2/2.
|
||||
* Created by ehlxr on 2018/2/2.
|
||||
*/
|
||||
public class TokenServerUtil {
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr.utils;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/3/18.
|
||||
* Created by ehlxr on 2017/3/18.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
package me.ehlxr.utils;
|
||||
|
||||
/**
|
||||
* 自定义状态码
|
||||
*
|
||||
* @author ehlxr
|
||||
* @since 2020/3/18.
|
||||
*/
|
||||
public enum Code {
|
||||
/**
|
||||
* 成功
|
||||
*/
|
||||
SUCCESSFUL(200, "success"),
|
||||
|
||||
/**
|
||||
* 未知异常
|
||||
*/
|
||||
UNKNOWN_EXCEPTION(600, "unknown server exception"),
|
||||
|
||||
/**
|
||||
* 请求参数不能为空
|
||||
*/
|
||||
REQUEST_PARAM_NULL_EXCEPTION(601, "required param should not be null"),
|
||||
|
||||
/**
|
||||
* 业务异常
|
||||
*/
|
||||
SERVICE_EXCEPTION(602, "service exception");
|
||||
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
|
||||
Code(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Code{" +
|
||||
"code=" + code +
|
||||
", message='" + message + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
private static final Code[] CODES = Code.values();
|
||||
|
||||
public static Code code(int code) {
|
||||
for (Code c : CODES) {
|
||||
if (code == c.getCode()) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
package me.ehlxr.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* Java 执行 shell 命令
|
||||
*
|
||||
* @author ehlxr
|
||||
* @since 2020/5/6.
|
||||
*/
|
||||
public class ExecShell {
|
||||
private static final Logger log = LoggerFactory.getLogger(ExecShell.class);
|
||||
public static void execShellCommand(final String command) {
|
||||
Process process = null;
|
||||
DataOutputStream dataOutputStream = null;
|
||||
try {
|
||||
process = Runtime.getRuntime().exec("/bin/sh");
|
||||
dataOutputStream = new DataOutputStream(process.getOutputStream());
|
||||
dataOutputStream.writeBytes(command + "\n");
|
||||
dataOutputStream.writeBytes("exit\n");
|
||||
dataOutputStream.flush();
|
||||
readStdStream(process);
|
||||
process.waitFor();
|
||||
} catch (IOException | InterruptedException | IllegalMonitorStateException e) {
|
||||
log.error("execShellCommand: {} error", command, e);
|
||||
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (dataOutputStream != null) {
|
||||
dataOutputStream.close();
|
||||
}
|
||||
if (process != null) {
|
||||
process.destroy();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("execShellCommand: {} close stream error", command, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取 Shell 进程标准输出流和错误流
|
||||
*/
|
||||
private static void readStdStream(final Process process) {
|
||||
String readLine;
|
||||
BufferedReader stdInput = null;
|
||||
BufferedReader stdError = null;
|
||||
try {
|
||||
// 读取Shell进程标准输出流
|
||||
stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
while ((readLine = stdInput.readLine()) != null) {
|
||||
log.info("[stdInputStream]: {}", readLine);
|
||||
}
|
||||
// 读取Shell进程标准错误流
|
||||
stdError = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
while ((readLine = stdError.readLine()) != null) {
|
||||
log.error("[stdErrorStream]: {}", readLine);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("readStdStream error", e);
|
||||
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (stdInput != null) {
|
||||
stdInput.close();
|
||||
}
|
||||
if (stdError != null) {
|
||||
stdError.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("readStdStream close stream error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ExecShell.execShellCommand("pwd");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package me.ehlxr.utils;
|
||||
|
||||
/**
|
||||
* FORM 表单提交类型
|
||||
*
|
||||
* @author ehlxr
|
||||
* @since 2020/4/27.
|
||||
*/
|
||||
public enum FormType {
|
||||
/**
|
||||
* form 表单提交类型
|
||||
*/
|
||||
FILE, STRING
|
||||
}
|
|
@ -7,7 +7,7 @@ import java.util.HashMap;
|
|||
/**
|
||||
* GeoHash算法实现
|
||||
*
|
||||
* @author lixiangrong
|
||||
* @author ehlxr
|
||||
*
|
||||
* 1、GeoHash将经纬度转换成一个可以排序,可以比较的字符串编码
|
||||
* 2、GeoHash表示的并不是一个点,而是一个矩形区域。比如编码wx4g0ec19,它表示的是一个矩形区域
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package me.ehlxr.utils;
|
||||
|
||||
/**
|
||||
* @author ehlxr
|
||||
* @since 2020/5/19.
|
||||
*/
|
||||
public enum HttpContentType {
|
||||
/**
|
||||
* key
|
||||
*/
|
||||
KEY("Content-Type"),
|
||||
/**
|
||||
* JSON
|
||||
*/
|
||||
JSON("application/json; charset=utf-8"),
|
||||
/**
|
||||
* form data
|
||||
*/
|
||||
FORMBODY("application/x-www-form-urlencoded");
|
||||
|
||||
HttpContentType(String v) {
|
||||
this.v = v;
|
||||
}
|
||||
|
||||
private String v;
|
||||
|
||||
public String value() {
|
||||
return v;
|
||||
}
|
||||
|
||||
public void setV(String v) {
|
||||
this.v = v;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,116 @@
|
|||
package me.ehlxr.utils;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import okhttp3.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author ehlxr
|
||||
* @since 2020/4/20.
|
||||
*/
|
||||
public class HttpUtil {
|
||||
private static final OkHttpClient OK_HTTP_CLIENT = new OkHttpClient.Builder()
|
||||
.connectTimeout(1, TimeUnit.MINUTES)
|
||||
.readTimeout(1, TimeUnit.MINUTES)
|
||||
.build();
|
||||
|
||||
public static String get(String url, Map<String, String> headers) {
|
||||
String resp;
|
||||
try {
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.headers(Headers.of(headers))
|
||||
.build();
|
||||
Response response = OK_HTTP_CLIENT.newCall(request).execute();
|
||||
if (response.isSuccessful()) {
|
||||
resp = response.body() != null ? response.body().string() : "";
|
||||
} else {
|
||||
throw new RuntimeException("send get http request failed. Unexpected code: " + response);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("send get http request failed.", e);
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
public static String get(String url) {
|
||||
return get(url, Maps.newHashMap());
|
||||
}
|
||||
|
||||
public static String post(String url, Map<String, String> headers, String body) {
|
||||
String resp;
|
||||
try {
|
||||
MediaType mediaType = MediaType.parse(headers.getOrDefault(HttpContentType.KEY.value(), HttpContentType.JSON.value()));
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.headers(Headers.of(headers))
|
||||
.post(RequestBody.create(mediaType, body))
|
||||
.build();
|
||||
|
||||
Response response = OK_HTTP_CLIENT.newCall(request).execute();
|
||||
if (response.isSuccessful()) {
|
||||
resp = response.body() != null ? response.body().string() : "";
|
||||
} else {
|
||||
throw new RuntimeException("send post http request failed. Unexpected code: " + response);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("send post http request failed.", e);
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
public static String post(String url, String body) {
|
||||
return post(url, Maps.newHashMap(), body);
|
||||
}
|
||||
|
||||
public static String formPost(String url, Map<String, Map<FormType, Object>> params) {
|
||||
return formPost(url, params, Maps.newHashMap());
|
||||
}
|
||||
|
||||
public static String formPost(String url, Map<String, Map<FormType, Object>> params, Map<String, String> header) {
|
||||
String resp;
|
||||
try {
|
||||
MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
|
||||
params.forEach((key, value) -> value.forEach((k, v) -> {
|
||||
if (k.equals(FormType.FILE)) {
|
||||
File file = (File) v;
|
||||
builder.addFormDataPart(
|
||||
key,
|
||||
file.getName(),
|
||||
RequestBody.create(MediaType.parse("application/octet-stream"), file));
|
||||
} else if (k.equals(FormType.STRING)) {
|
||||
builder.addFormDataPart(key, String.valueOf(v));
|
||||
}
|
||||
}));
|
||||
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.post(builder.build())
|
||||
.headers(Headers.of(header))
|
||||
.build();
|
||||
Response response = OK_HTTP_CLIENT.newCall(request).execute();
|
||||
if (response.isSuccessful()) {
|
||||
resp = response.body() != null ? response.body().string() : "";
|
||||
} else {
|
||||
throw new RuntimeException("send multipart post http request failed. Unexpected code: " + response);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("send multipart post http request failed.", e);
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
|
||||
public static String appendParam(Map<String, Object> param) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
param.forEach((k, v) -> sb.append(k).append("=").append(v).append("&"));
|
||||
|
||||
return sb.substring(0, sb.length() - 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,225 @@
|
|||
package me.ehlxr.utils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.*;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* JSON 处理类
|
||||
*
|
||||
* @author ehlxr
|
||||
* @since 2020/5/6.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class JsonUtils {
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
private static final String STANDARD_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
static {
|
||||
// 对象的所有字段全部列入
|
||||
OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.ALWAYS);
|
||||
// 取消默认转换 timestamps 形式
|
||||
OBJECT_MAPPER.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
// 忽略空 bean 转 JSON 的错误
|
||||
OBJECT_MAPPER.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
// 所有的日期格式都统一为以下的样式:yyyy-MM-dd HH:mm:ss
|
||||
OBJECT_MAPPER.setDateFormat(new SimpleDateFormat(STANDARD_FORMAT));
|
||||
// 忽略在 JSON 字符串中存在,但是在 java 对象中不存在对应属性的情况
|
||||
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
}
|
||||
|
||||
public static ObjectMapper om() {
|
||||
return OBJECT_MAPPER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转为 JsonNode 实例
|
||||
*
|
||||
* @param obj 要转换的对象
|
||||
* @param <T> 要转换的对象类型
|
||||
* @return {@link JsonNode}实例
|
||||
*/
|
||||
public static <T> JsonNode obj2JsonNode(T obj) {
|
||||
try {
|
||||
return OBJECT_MAPPER.readTree(obj2String(obj));
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转为 JSON 字符串
|
||||
*
|
||||
* @param obj 要转换的对象
|
||||
* @param <T> 要转换的对象类型
|
||||
* @return JSON 字符串
|
||||
*/
|
||||
public static <T> String obj2String(T obj) {
|
||||
if (obj == null) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return obj instanceof String ? (String) obj : OBJECT_MAPPER.writeValueAsString(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转为格式化的 JSON 字符串
|
||||
*
|
||||
* @param obj 要转换的对象
|
||||
* @param <T> 要转换的对象类型
|
||||
* @return 格式化的 JSON 字符串
|
||||
*/
|
||||
public static <T> String obj2StringPretty(T obj) {
|
||||
if (obj == null) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
return obj instanceof String ? (String) obj : OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(obj);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转换为自定义对象
|
||||
*
|
||||
* @param str 要转换的字符串
|
||||
* @param clazz 自定义对象的 class 对象
|
||||
* @param <T> 自定义对象类型
|
||||
* @return 自定义对象
|
||||
*/
|
||||
public static <T> T string2Obj(String str, Class<T> clazz) {
|
||||
if (Strings.isNullOrEmpty(str) || clazz == null) {
|
||||
throw new RuntimeException("json string to obj param should not empty");
|
||||
}
|
||||
try {
|
||||
return clazz.equals(String.class) ? (T) str : OBJECT_MAPPER.readValue(str, clazz);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转换为自定义对象
|
||||
*
|
||||
* @param str 要转换的字符串
|
||||
* @param typeReference 集合对象 typeReference
|
||||
* @param <T> 集合对象类型
|
||||
* @return 自定义对象
|
||||
*/
|
||||
public static <T> T string2Obj(String str, TypeReference<T> typeReference) {
|
||||
if (Strings.isNullOrEmpty(str) || typeReference == null) {
|
||||
throw new RuntimeException("json string to obj param should not empty");
|
||||
}
|
||||
try {
|
||||
return typeReference.getType().equals(String.class) ? (T) str : OBJECT_MAPPER.readValue(str, typeReference);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转换为自定义对象
|
||||
*
|
||||
* @param str 要转换的字符串
|
||||
* @param collectionClazz 集合 class
|
||||
* @param elementClazzes 集合对象 class
|
||||
* @param <T> 集合对象类型
|
||||
* @return 自定义对象
|
||||
*/
|
||||
public static <T> T string2Obj(String str, Class<?> collectionClazz, Class<?>... elementClazzes) {
|
||||
JavaType javaType = OBJECT_MAPPER.getTypeFactory().constructParametricType(collectionClazz, elementClazzes);
|
||||
try {
|
||||
return OBJECT_MAPPER.readValue(str, javaType);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试类
|
||||
*/
|
||||
static class User {
|
||||
private Integer id;
|
||||
private String email;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
User user1 = new User();
|
||||
user1.setId(1);
|
||||
user1.setEmail("xrv@live.com");
|
||||
|
||||
String userJsonstr = JsonUtils.obj2String(user1);
|
||||
System.out.println(userJsonstr);
|
||||
|
||||
String userJsonPretty = JsonUtils.obj2StringPretty(user1);
|
||||
System.out.println(userJsonPretty);
|
||||
|
||||
User user2 = JsonUtils.string2Obj(userJsonstr, User.class);
|
||||
user2.setId(2);
|
||||
user2.setEmail("ehlxr.me@gmail.com");
|
||||
|
||||
List<User> userList = new ArrayList<>();
|
||||
userList.add(user1);
|
||||
userList.add(user2);
|
||||
String userListJson = JsonUtils.obj2String(userList);
|
||||
System.out.println(userListJson);
|
||||
|
||||
List<User> userListBean = JsonUtils.string2Obj(userListJson, new TypeReference<List<User>>() {
|
||||
});
|
||||
if (userListBean != null) {
|
||||
userListBean.forEach(user -> System.out.println(user.getId() + " : " + user.getEmail()));
|
||||
}
|
||||
List<User> userListBean2 = JsonUtils.string2Obj(userListJson, List.class, User.class);
|
||||
if (userListBean2 != null) {
|
||||
userListBean2.forEach(user -> System.out.println(user.getId() + " : " + user.getEmail()));
|
||||
}
|
||||
|
||||
|
||||
Map<String, String> body = ImmutableMap.of("mobile", "13211111222", "realName", "realName");
|
||||
String obj2String = JsonUtils.obj2String(body);
|
||||
System.out.println(obj2String);
|
||||
|
||||
Map<String, String> stringStringMap = JsonUtils.string2Obj(obj2String, new TypeReference<Map<String, String>>() {
|
||||
});
|
||||
|
||||
stringStringMap.forEach((k, v) -> System.out.println(k + " : " + v));
|
||||
|
||||
JsonNode jsonNode = JsonUtils.obj2JsonNode(userList);
|
||||
System.out.println(jsonNode.path(0));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr.utils;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/3/15.
|
||||
* Created by ehlxr on 2017/3/15.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
|
|
|
@ -0,0 +1,149 @@
|
|||
package me.ehlxr.utils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 统一输出结果集
|
||||
*
|
||||
* @author ehlxr
|
||||
* @since 2020/3/18.
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class Result<T> implements Serializable {
|
||||
private static final long serialVersionUID = 2247338010219468245L;
|
||||
/**
|
||||
* 响应编码
|
||||
*/
|
||||
private int code;
|
||||
/**
|
||||
* 消息,如错误消息
|
||||
*/
|
||||
private String message;
|
||||
/**
|
||||
* 数据内容
|
||||
*/
|
||||
private T data;
|
||||
|
||||
private Result() {
|
||||
}
|
||||
|
||||
private Result(int code, T data, String message) {
|
||||
this.code = code;
|
||||
this.data = data;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public static <T> Result<T> success(T data, String message) {
|
||||
return new Result<>(Code.SUCCESSFUL.getCode(), data, message);
|
||||
}
|
||||
|
||||
public static <T> Result<T> success(T data) {
|
||||
return success(data, null);
|
||||
}
|
||||
|
||||
public static <T> Result<T> success() {
|
||||
return success(null);
|
||||
}
|
||||
|
||||
public static <T> Result<T> of(int c, T d, String m) {
|
||||
return new Result<>(c, d, m);
|
||||
}
|
||||
|
||||
public static <T> Result<T> of(Code c, T d, String m) {
|
||||
return new Result<>(c.getCode(), d, m);
|
||||
}
|
||||
|
||||
public static <T> Result<T> fail(Code code, String message) {
|
||||
return of(code.getCode(), null, message);
|
||||
}
|
||||
|
||||
public static <T> Result<T> fail(Code code) {
|
||||
return fail(code, code.getMessage());
|
||||
}
|
||||
|
||||
public static <T> Result<T> fail(Throwable e) {
|
||||
// 格式化异常消息,防止输出异常栈信息到结果集
|
||||
e = Throwables.getRootCause(e);
|
||||
return of(Code.UNKNOWN_EXCEPTION.getCode(), null, String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage()));
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
// return Strings.isNullOrEmpty(m) ? c.getMessage() : m;
|
||||
if (Strings.isNullOrEmpty(message)) {
|
||||
Code code;
|
||||
try {
|
||||
code = Code.code(this.code);
|
||||
} catch (Exception e) {
|
||||
return message;
|
||||
}
|
||||
|
||||
return Objects.isNull(code) ? "" : code.getMessage();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
// return Objects.nonNull(c) ? c.getCode() : Code.UNKNOWN_EXCEPTION.getCode();
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Result<?> result = (Result<?>) o;
|
||||
return code == result.code &&
|
||||
Objects.equals(message, result.message) &&
|
||||
Objects.equals(data, result.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
try {
|
||||
ObjectMapper om = new ObjectMapper();
|
||||
// 取消时间的转化格式, 默认是时间戳
|
||||
om.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
|
||||
// 设置时间格式
|
||||
om.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
|
||||
om.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
om.configure(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED, false);
|
||||
return om.writeValueAsString(this);
|
||||
} catch (JsonProcessingException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(success());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package me.ehlxr.utils;
|
||||
|
||||
/**
|
||||
* Created by lixiangrong on 2017/8/17.
|
||||
* Created by ehlxr on 2017/8/17.
|
||||
* 字符串对齐器。可以指定对齐格式和一行的最大字符数 对齐格式有左对齐、居中、右对齐
|
||||
*/
|
||||
public class StringAlign {
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
|
||||
|
||||
<!-- 配置扫描路径 -->
|
||||
<context:component-scan base-package="osc.git.eh3.springamq">
|
||||
<context:component-scan base-package="me.ehlxr.springamq">
|
||||
<!-- 只扫描Service,也可以添加Repostory,但是要把Controller排除在外,Controller由spring-mvc.xml去加载 -->
|
||||
<!-- <context:include-filter type="annotation" expression="org.springframework.stereotype.Service" /> -->
|
||||
<!-- <context:include-filter type="annotation" expression="org.springframework.stereotype.Repository" /> -->
|
||||
|
|
Loading…
Reference in New Issue