mongodb文件上传
This commit is contained in:
parent
f77499db29
commit
e1be7c7523
|
|
@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication;
|
|||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import com.bonus.common.security.annotation.EnableRyFeignClients;
|
||||
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
||||
|
||||
/**
|
||||
* 认证授权中心
|
||||
|
|
@ -11,7 +12,7 @@ import com.bonus.common.security.annotation.EnableRyFeignClients;
|
|||
* @author bonus
|
||||
*/
|
||||
@EnableRyFeignClients
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class })
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, MongoAutoConfiguration.class })
|
||||
public class BonusAuthApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.bonus.common.core.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.text.*;
|
||||
import java.time.*;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,197 @@
|
|||
package com.bonus.common.core.utils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.Blob;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
/**
|
||||
* @author HeiZi
|
||||
*/
|
||||
public class StringHelper {
|
||||
|
||||
private static final String HEX_STRING = "0123456789ABCDEF";
|
||||
|
||||
public static String replaceAll(String str, String oldStr, String newStr) {
|
||||
return str.replaceAll(oldStr, newStr);
|
||||
}
|
||||
|
||||
public static boolean contains(String s1, String s2) {
|
||||
if (isEmpty(s1)) {
|
||||
return false;
|
||||
}
|
||||
return s1.contains(s2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 集合转数组
|
||||
*
|
||||
* @param list
|
||||
* @param separator
|
||||
* @return
|
||||
*/
|
||||
public static String listToString(List<String> list, char separator) {
|
||||
return StringUtils.join(list.toArray(), separator);
|
||||
}
|
||||
|
||||
public static void writeText(String args) {
|
||||
File fp = new File("F:\\1.txt");
|
||||
PrintWriter pfp;
|
||||
try {
|
||||
pfp = new PrintWriter(fp);
|
||||
pfp.print(args);
|
||||
pfp.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* blob中文乱码转码
|
||||
* @return
|
||||
*/
|
||||
public static String blobToStrings(Blob b) {
|
||||
try {
|
||||
if(b == null) {
|
||||
return null;
|
||||
}
|
||||
String content = new String(b.getBytes((long) 1, (int) b.length()), "UTF-8");
|
||||
return content;
|
||||
} catch (SQLException | UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* blob中文乱码转码
|
||||
*
|
||||
* @param content
|
||||
* @return
|
||||
*/
|
||||
public static String blobToString(String content) {
|
||||
try {
|
||||
return new String(content.getBytes("ISO_8859_1"), "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* unicode转字符串
|
||||
*
|
||||
* @param unicode
|
||||
* @return
|
||||
*/
|
||||
public static String unicodeToString(String unicode) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
String[] hex = unicode.split("\\\\u");
|
||||
for (int i = 1; i < hex.length; i++) {
|
||||
int index = Integer.parseInt(hex[i], 16);
|
||||
sb.append((char) index);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* * 含有unicode 的字符串转一般字符串 * @param unicodeStr 混有 Unicode 的字符串
|
||||
* * @return
|
||||
*/
|
||||
public static String unicodeStr2String(String unicodeStr) {
|
||||
int length = unicodeStr.length();
|
||||
int count = 0;
|
||||
// 正则匹配条件,可匹配“\\u”1到4位,一般是4位可直接使用 String regex = "\\\\u[a-f0-9A-F]{4}";
|
||||
String regex = "\\\\u[a-f0-9A-F]{1,4}";
|
||||
Pattern pattern = Pattern.compile(regex);
|
||||
Matcher matcher = pattern.matcher(unicodeStr);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
|
||||
while (matcher.find()) {
|
||||
String oldChar = matcher.group();
|
||||
String newChar = unicode2String(oldChar);
|
||||
int index = matcher.start();
|
||||
sb.append(unicodeStr.substring(count, index));
|
||||
sb.append(newChar);
|
||||
count = index + oldChar.length();
|
||||
}
|
||||
sb.append(unicodeStr.substring(count, length));
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* unicode 转字符串
|
||||
* 全为 Unicode 的字符串
|
||||
* @param unicode
|
||||
* @return
|
||||
*/
|
||||
public static String unicode2String(String unicode) {
|
||||
StringBuffer string = new StringBuffer();
|
||||
String[] hex = unicode.split("\\\\u");
|
||||
|
||||
for (int i = 1; i < hex.length; i++) {
|
||||
// 转换出每一个代码点
|
||||
int data = Integer.parseInt(hex[i], 16);
|
||||
// 追加成string
|
||||
string.append((char) data);
|
||||
}
|
||||
|
||||
return string.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串编码成16进制数字,适用于所有字符(包括中文)
|
||||
*/
|
||||
public static String encode(String str) {
|
||||
// 根据默认编码获取字节数组
|
||||
byte[] bytes = str.getBytes();
|
||||
StringBuilder sb = new StringBuilder(bytes.length * 2);
|
||||
// 将字节数组中每个字节拆解成2位16进制整数
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
sb.append(HEX_STRING.charAt((bytes[i] & 0xf0) >> 4));
|
||||
sb.append(HEX_STRING.charAt((bytes[i] & 0x0f) >> 0));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String decode(String bytes) {
|
||||
int num=2;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(bytes.length() / num);
|
||||
// 将每2位16进制整数组装成一个字节
|
||||
for (int i = 0; i < bytes.length(); i += num){
|
||||
baos.write((HEX_STRING.indexOf(bytes.charAt(i)) << 4 | HEX_STRING.indexOf(bytes.charAt(i + 1))));
|
||||
}
|
||||
|
||||
return new String(baos.toByteArray());
|
||||
}
|
||||
|
||||
public static String fillPrefixZero(int v, int len) {
|
||||
String vStr = v + "";
|
||||
StringBuilder tst=new StringBuilder("0");
|
||||
while (vStr.length() < len) {
|
||||
vStr =tst.append(vStr).toString();
|
||||
}
|
||||
return vStr;
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String str) {
|
||||
return str == null || "".equals(str.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断字符串 不为空
|
||||
*/
|
||||
public static boolean isNotEmpty(String str) {
|
||||
return !isEmpty(str);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.bonus.bracelet.service.impl;
|
|||
|
||||
import com.bonus.bracelet.mapper.PersonMgeMapper;
|
||||
import com.bonus.bracelet.service.IPersonMgeService;
|
||||
import com.bonus.system.api.RemoteFileService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -18,4 +19,7 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
|
|||
|
||||
@Resource(name = "PersonMgeMapper")
|
||||
private PersonMgeMapper mapper;
|
||||
|
||||
@Resource
|
||||
private RemoteFileService remoteFileService;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
import com.bonus.common.security.annotation.EnableCustomConfig;
|
||||
import com.bonus.common.security.annotation.EnableRyFeignClients;
|
||||
import com.bonus.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
||||
|
||||
/**
|
||||
* 系统模块
|
||||
|
|
@ -14,7 +15,7 @@ import com.bonus.common.swagger.annotation.EnableCustomSwagger2;
|
|||
@EnableCustomConfig
|
||||
@EnableCustomSwagger2
|
||||
@EnableRyFeignClients
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(exclude = MongoAutoConfiguration.class )
|
||||
public class BonusSystemApplication
|
||||
{
|
||||
public static void main(String[] args)
|
||||
|
|
|
|||
Loading…
Reference in New Issue