list = new ArrayList<>();
82 | String line;
83 | try (BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8"))) {
84 | while ((line = br.readLine()) != null) {
85 | if ("".equals(line) || line.contains("#")) {
86 | } else {
87 | list.add(line);
88 | }
89 | }
90 | } catch (Exception e) {
91 | e.getLocalizedMessage();
92 | }
93 |
94 | return list;
95 | }
96 |
97 | public static String GenerateFile(String imgSource, String savePath, String saveName, HttpServletRequest request) throws IOException {
98 | return null;
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/springbootdemo-token/src/main/java/com/example/springbootdemotoken/utils/RedisCacheUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootdemotoken.utils;
2 |
3 | import org.springframework.beans.factory.annotation.Autowired;
4 | import org.springframework.stereotype.Component;
5 | import redis.clients.jedis.JedisCluster;
6 |
7 | import javax.annotation.PostConstruct;
8 | import java.io.IOException;
9 |
10 | @Component
11 | public class RedisCacheUtil {
12 | @Autowired
13 | private JedisCluster jed;
14 |
15 | private static JedisCluster jedisCluster;
16 |
17 | public static JedisCluster getInstance(){
18 | return jedisCluster;
19 | }
20 |
21 | @PostConstruct
22 | public void init(){
23 | this.jedisCluster = jed;
24 | }
25 | public static boolean exists(String prefix,String key){
26 | if(jedisCluster.exists(prefix+key)){
27 | return true;
28 | }else{
29 | return false;
30 | }
31 | }
32 | public static boolean exists(String key){
33 | if(jedisCluster.exists(key)){
34 | return true;
35 | }else{
36 | return false;
37 | }
38 | }
39 | /**
40 | * 取出 缓存 数据
41 | * @param key
42 | * @return
43 | */
44 | public static String get(String prefix,String key) {
45 | String value = jedisCluster.get(prefix+key);
46 | return value;
47 | }
48 | public static String get(String key) {
49 | String value = jedisCluster.get(key);
50 | return value;
51 | }
52 | /**
53 | * 存入缓存数据
54 | * @param key
55 | * @param value
56 | */
57 | public static void set(String prefix,String key,String value) {
58 | jedisCluster.set(prefix+key, value);
59 | }
60 | public static void set(String key,String value) {
61 | jedisCluster.set(key, value);
62 | }
63 |
64 | /**
65 | * 删除 key 存贮
66 | * @param key
67 | * @return
68 | */
69 | public static Long del(String prefix,String key) {
70 | Long value = jedisCluster.del(prefix+key);
71 | return value;
72 | }
73 | public static Long del(String key) {
74 | Long value = jedisCluster.del(key);
75 | return value;
76 | }
77 |
78 | /**
79 | * 关闭redis连接
80 | */
81 | private static void closeJedis(JedisCluster jedisCluster) {
82 | if (jedisCluster != null) {
83 | try {
84 | jedisCluster.close();
85 | } catch (IOException e) {
86 | e.printStackTrace();
87 | }
88 | }
89 | }
90 | /**
91 | * 设置 过期时间 单位秒
92 | * @param key
93 | * @param value
94 | * @param seconds
95 | * @return
96 | */
97 | public static void setTimeSecond(String key,String value,int seconds ) {
98 | jedisCluster.setex(key, seconds, value);
99 | }
100 | /**
101 | * 设置 过期时间 单位毫秒
102 | * @param key
103 | * @param value
104 | * @param milliseconds
105 | * @return
106 | */
107 | public static void setTimeMilliseconds(String key,String value,long milliseconds ) {
108 | jedisCluster.psetex(key, milliseconds, value);
109 | }
110 | /**
111 | * 设置 过期时间 以天为单位
112 | * @param key
113 | * @param value
114 | * @param day
115 | * @return
116 | **/
117 | public static void setTimeDay(String key,String value,int day ) {
118 | jedisCluster.psetex(key, day*24*60*60, value);
119 | }
120 | /**
121 | * 设置 过期时间 以小时为单位
122 | * @param key
123 | * @param value
124 | * @param Hour
125 | * @return
126 | **/
127 | public static void setTimeHour(String key,String value,int Hour ) {
128 | jedisCluster.psetex(key, Hour*60*60, value);
129 | }
130 | /**
131 | * 设置 过期时间 以分钟为单位
132 | * @param key
133 | * @param value
134 | * @param minute
135 | * @return
136 | **/
137 | public static void setTimeMinute(String key,String value,int minute ) {
138 | jedisCluster.psetex(key, minute*60, value);
139 | String string = jedisCluster.get(key);
140 | System.out.println(string);
141 |
142 | }
143 |
144 | /**
145 | * 自增:计数
146 | * @param key 已保存的key值
147 | */
148 | public static void incr(String key){
149 | jedisCluster.incr(key);
150 |
151 | }
152 | }
153 |
--------------------------------------------------------------------------------
/springbootdemo-token/src/main/java/com/example/springbootdemotoken/utils/StrUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootdemotoken.utils;
2 |
3 | import org.apache.commons.lang.StringUtils;
4 |
5 | import java.math.BigDecimal;
6 | import java.util.ArrayList;
7 | import java.util.Arrays;
8 | import java.util.List;
9 |
10 | /**
11 | *
12 | * @description 字符串工具类
13 | * @author zxr
14 | * @date 2017 下午1:13:46
15 | */
16 | public class StrUtil extends StringUtils {
17 |
18 | /**
19 | * 处理从Map中取出的Null值,默认返回空字符串
20 | *
21 | * Map: {name=sinba,age=11}
22 | * StrUtil.fixNull( map.get("noSuchKey") ) = ""
23 | * StrUtil.fixNull( map.get("name") ) = "sinba"
24 | * StrUtil.fixNull( map.get("age") ) = "11"
25 | * @param o
26 | * @return
27 | *
28 | */
29 | public static String fixNull(Object o) {
30 | return o == null ? "" : o.toString().trim();
31 | }
32 |
33 | /**
34 | * 处理空值
35 | * @param o
36 | * @param defaulStr
37 | * @return
38 | */
39 | public static String fixNull(Object o, String defaulStr) {
40 | return o == null ? defaulStr : o.toString().trim();
41 | }
42 |
43 | /**
44 | * 处理BigDecimal Null值
45 | * @param value
46 | * @return
47 | */
48 | public static BigDecimal fixBigDecimal(BigDecimal value) {
49 | if (value == null) {
50 | return BigDecimal.ZERO;
51 | }
52 | return value;
53 | }
54 |
55 | /**
56 | * 去掉字符串前面的空格
57 | * @param original
58 | * @return
59 | */
60 | public static String beforeTrim(String original) {
61 | if (original == null || original.trim().length() == 0) {
62 | return original;
63 | }
64 | int len = original.length();
65 | int st = 0;
66 | int off = 0; /* avoid getfield opcode */
67 | char[] originalValue = original.toCharArray();
68 | char[] val = Arrays.copyOfRange(originalValue, off, off + len);
69 | ; /* avoid getfield opcode */
70 |
71 | while ((st < len) && (val[off + st] <= ' ')) {
72 | st++;
73 | }
74 | return ((st > 0) || (st < len)) ? original.substring(st, len) : "";
75 | }
76 |
77 | /**
78 | * 去掉字符串后面的空格
79 | * @param original
80 | * @return
81 | */
82 | public static String afterTrim(String original) {
83 | if (original == null || original.trim().length() == 0) {
84 | return original;
85 | }
86 | int len = original.length();
87 | int st = 0;
88 | int off = 0; /* avoid getfield opcode */
89 | char[] originalValue = original.toCharArray();
90 | char[] val = Arrays.copyOfRange(originalValue, off, off + len); /* avoid getfield opcode */
91 |
92 | while ((st < len) && (val[off + len - 1] <= ' ')) {
93 | len--;
94 | }
95 | return ((st > 0) || (st < len)) ? original.substring(st, len) : "";
96 | }
97 |
98 | /**
99 | * 字符串转list
100 | * @param str
101 | * @param splitBy
102 | * @return
103 | */
104 | public static List splitToList(String str, String splitBy) {
105 | if (StringUtils.isBlank(str)) {
106 | return null;
107 | }
108 | String[] arrays = str.split(splitBy);
109 | List list = new ArrayList();
110 | for (int i = 0; i < arrays.length; i++) {
111 | list.add(arrays[i].trim());
112 | }
113 | return list;
114 | }
115 |
116 | /**
117 | *
118 | * @param str
119 | * @param splitBy
120 | * @return
121 | */
122 | public static List splitToLongList(String str, String splitBy) {
123 | if (StringUtils.isBlank(str)) {
124 | return null;
125 | }
126 | String[] arrays = str.split(splitBy);
127 | List list = new ArrayList();
128 | for (int i = 0; i < arrays.length; i++) {
129 | list.add(Long.parseLong(arrays[i].trim()));
130 | }
131 | return list;
132 | }
133 |
134 | /**
135 | * 将数据库表字段转化为实体类属性
136 | * e.g. user_info --> userInfo
137 | * @param columnName
138 | * @return
139 | */
140 | public static String toCamelStyle(String columnName) {
141 | StringBuffer sb = new StringBuffer();
142 | boolean match = false;
143 | for (int i = 0; i < columnName.length(); i++) {
144 | char ch = columnName.charAt(i);
145 | if (match && ch >= 97 && ch <= 122) {
146 | ch -= 32;
147 | }
148 | if (ch != '_') {
149 | match = false;
150 | sb.append(ch);
151 | } else {
152 | match = true;
153 | }
154 | }
155 | return sb.toString();
156 | }
157 |
158 | /**
159 | * 将驼峰命名法转化为下划线的形式
160 | * e.g. UserInfo --> user_info loginId --> login_id
161 | * @param name
162 | * @return
163 | */
164 | public static String addUnderscores(String name) {
165 | StringBuffer buf = new StringBuffer(name.replace('.', '_'));
166 | for (int i = 1; i < buf.length() - 1; i++) {
167 | if (Character.isLowerCase(buf.charAt(i - 1)) && Character.isUpperCase(buf.charAt(i)) && Character.isLowerCase(buf.charAt(i + 1))) {
168 | buf.insert(i++, '_');
169 | }
170 | }
171 | return buf.toString().toLowerCase();
172 | }
173 |
174 | }
175 |
--------------------------------------------------------------------------------
/springbootdemo-token/src/main/java/com/example/springbootdemotoken/webController/WebController.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootdemotoken.webController;
2 |
3 |
4 | import com.example.springbootdemotoken.tokens.JsonWebToken;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RestController;
7 |
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 | /**
12 | * @Title: WebController
13 | * @ProjectName springbootdemo
14 | * @Description: TODO
15 | * @author YangPeng
16 | * @company ccxcredit
17 | * @date 2019/9/26-17:17
18 | */
19 | @RestController
20 | public class WebController {
21 |
22 | @RequestMapping(value = "/getStr")
23 | public String getStr(String str){
24 | Map map = new HashMap<>();
25 | map.put("name","yangpeng");
26 | map.put("userId","123221");
27 | String token = JsonWebToken.createToken(map);
28 | return token+"----";
29 | }
30 |
31 | @RequestMapping(value = "/crossToken")
32 | public String crossToken(){
33 | return "token验证成功";
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/springbootdemo-token/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 7006
3 | servlet:
4 | context-path: /token
5 | eureka:
6 | client:
7 | service-url:
8 | defaultZone: http://localhost:5060/eureka/eureka
9 | spring:
10 | redis:
11 | cluster:
12 | expire-seconds: 120
13 | command-timeout: 5000
14 | nodes: namenode22:6379,datanode23:6379,datanode24:6379,datanode25:6379,datanode26:6379,datanode27:6379
15 |
--------------------------------------------------------------------------------
/springbootdemo-token/src/main/resources/static/tokenWhite.txt:
--------------------------------------------------------------------------------
1 | /web
2 | /getStr
--------------------------------------------------------------------------------
/springbootdemo-token/src/test/java/com/example/springbootdemotoken/SpringbootdemoTokenApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.example.springbootdemotoken;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class SpringbootdemoTokenApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------