package com.yang.mall.tools;
/**
* Created by chijr on 16/11/5.
*/
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.bson.types.ObjectId;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
//import sun.misc.BASE64Encoder;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.math.BigDecimal;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Utils {
private static SerializeConfig mapping = new SerializeConfig();
private static String dateFormat;
static {
dateFormat = "yyyy-MM-dd HH:mm:ss";
mapping.put(Date.class, new SimpleDateFormatSerializer(dateFormat));
}
public Utils() {
}
public static Date getDateZero(Date dt){
Calendar calendar = Calendar.getInstance();
calendar.setTime(dt);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
Date zero = calendar.getTime();
return zero;
}
public static Date dateAddDay(Date dt,int d){
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH, d);
return c.getTime();
}
// public static String encodePassword(String password){
//
// return MD5.md5(password+JWTUtils.base64Secret);
//
// }
public static int parseInt(String intString) {
intString = StringUtils.trim(intString);
if (StringUtils.isEmpty(intString)) {
return 0;
}
int value = 0;
try {
value = Integer.parseInt(intString);
} catch (Exception e) {
System.err.println("字符串转换数据出错:原始数据是:"+intString+" 出错原因:"
+e.getMessage());
return value;
}
return value;
}
public static double parseDouble(String doubleString) {
if (StringUtils.isEmpty(doubleString)) {
return 0.0;
}
double value = 0.0;
try {
value = Double.parseDouble(doubleString);
} catch (Exception e) {
return value;
}
return value;
}
public static String mapToUrl(String baseUrl, Map<String, String> newParams) {
MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
params.setAll(newParams);
UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(baseUrl).queryParams(params).build();
return uriComponents.toString();
}
//get request headers
public static Map<String, String> getHeaders(HttpServletRequest request) {
Map<String, String> map = new HashMap<String, String>();
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = (String) headerNames.nextElement();
String value = request.getHeader(key);
map.put(key, value);
}
return map;
}
public static String safeString(String filePath) {
if (StringUtils.isEmpty(filePath)) {
return "";
}
return filePath;
}
public static String safeStringArray(String[] array, int pos) {
if (array == null) {
return "";
}
if ((array.length - 1) < pos) {
return "";
}
return StringUtils.trim(array[pos]);
}
public static List<String> readLines(String filePath) {
ArrayList<String> strs = new ArrayList<String>();
BufferedReader br = null;
String temp = "";
try {
br = new BufferedReader(new FileReader(filePath));
while ((temp = br.readLine()) != null) {
System.out.println(temp);
strs.add(temp);
}
} catch (FileNotFoundException e1) {
System.out.println("指定的文件不存在");
} catch (IOException e2) {
e2.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
br = null;
}
return strs;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}
public static String readString(String filePath) throws IOException
{
File file=new File(filePath);
FileInputStream inStream=new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer=new byte[1024];
int length=-1;
length = inStream.read(buffer);
while(length!=-1) {
bos.write(buffer,0,length);
length = inStream.read(buffer);
// .write方法 SDK 的解释是 Writes count bytes from the byte array buffer starting at offset index to this stream.
// 当流关闭以后内容依然存在
}
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
inStream.close();
} catch (IOException e) {
e.printStackTrace();
}
return bos.toString();
// 为什么不一次性把buffer得大小取出来呢?为什么还要写入到bos中呢? return new(buffer,"UTF-8") 不更好么?
// return new String(bos.toByteArray(),"UTF-8");
}
public static String excptionStackToString(Exception e){
StringWriter sw = null;
PrintWriter pw = null;
try {
sw = new StringWriter();
pw = new PrintWriter(sw);
//将出错的栈信息输出到printWriter中
e.printStackTrace(pw);
pw.flush();
sw.flush();
} finally {
if (sw != null) {
try {
sw.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (pw != null) {
pw.close();
}
}
return pw.toString();
}
public static String formatDateTime(Date dt) {
String tmstr = String.format("%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", dt);
return tmstr;
}
public static String timeString(Date date)
{
SimpleDateFormat sdf=new SimpleDateFormat("HH:mm");
return sdf.format(date);
}
public static String totalTimeString(Date date)
{
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
public static Date addDay(Date day ,int many){
Calendar ca = Calendar.getInstance();
ca.setTime(day);
ca.add(Calendar.DATE, many);
day = ca.getTime();
return day;
}
public static String getHashMD5(String source){
return Utils.getHash(source,"MD5");
}
public static String getHashSHA(String source){
return Utils.getHash(source,"SHA");
}
/**
* 由于MD5 与SHA-1均是从MD4 发展而来,它们的结构和强度等特性有很多相似之处
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
yang-mall-++i和i++ (314个子文件)
info-20190724.log.0 109KB
info-20190723.log.0 53KB
error-20190723.log.0 22KB
upload.bat 26B
mvnw.cmd 6KB
.gitignore 239B
.gitignore 176B
spring.log.2019-07-02.0.gz 111KB
spring.log.2019-07-15.0.gz 51KB
spring.log.2019-07-01.0.gz 32KB
spring.log.2022-10-31.0.gz 26KB
spring.log.2019-07-09.0.gz 17KB
spring.log.2019-06-27.0.gz 16KB
spring.log.2019-07-10.0.gz 16KB
spring.log.2022-10-21.0.gz 14KB
spring.log.2019-07-05.0.gz 12KB
spring.log.2019-07-18.0.gz 10KB
spring.log.2019-06-13.0.gz 9KB
spring.log.2019-06-26.0.gz 8KB
spring.log.2019-07-16.0.gz 7KB
spring.log.2019-07-24.0.gz 7KB
spring.log.2019-07-23.0.gz 5KB
spring.log.2019-07-19.0.gz 5KB
spring.log.2019-06-19.0.gz 5KB
spring.log.2019-07-12.0.gz 4KB
spring.log.2019-07-03.0.gz 4KB
spring.log.2019-06-22.0.gz 4KB
spring.log.2019-06-21.0.gz 3KB
spring.log.2019-06-20.0.gz 3KB
spring.log.2019-06-11.0.gz 3KB
spring.log.2019-06-14.0.gz 2KB
spring.log.2019-06-24.0.gz 2KB
spring.log.2019-06-12.0.gz 2KB
spring.log.2022-10-25.0.gz 370B
mall.iml 50KB
fruit-api.iml 15KB
mall.ipr 4KB
mall.iws 20KB
mail-1.4.7.jar 509KB
log4j-1.2.17.jar 478KB
aliyun-java-sdk-core-3.2.2.jar 83KB
Utils.java 28KB
EncryptUtils.java 17KB
HttpUtils.java 14KB
XmlUtils.java 10KB
LiveOrderServiceImpl.java 9KB
ResultMessage.java 7KB
WeChatUtils.java 6KB
AuthTokenFilter.java 6KB
BaseExceptionDefine.java 5KB
DateUtil.java 5KB
IdUtil.java 5KB
AesCbcUtil.java 5KB
LiveShopCartServiceImpl.java 5KB
MemberServiceImpl.java 4KB
GzSparkException.java 4KB
ProductServiceImpl.java 4KB
ResponseHelper.java 4KB
ProductSortServiceImpl.java 4KB
BeanUtils.java 4KB
JWTUtils.java 4KB
SwaggerConfig.java 3KB
ReturnMessagePackage.java 3KB
UploadAdminController.java 3KB
MD5Utils.java 3KB
MybatisPlusConfig.java 2KB
MAPIHttpServletRequestWrapper.java 2KB
Product.java 2KB
LiveOrderController.java 2KB
IProductService.java 2KB
LiveOrderLine.java 2KB
BannerServiceImpl.java 2KB
ProductAdminController.java 2KB
ConvertUtil.java 2KB
TenantShowWindowDTO.java 2KB
BannerAdminController.java 2KB
SysUserServiceImpl.java 2KB
LiveShopCartController.java 2KB
LiveOrder.java 2KB
ProductController.java 2KB
ILiveOrderService.java 2KB
Banner.java 2KB
SysUser.java 2KB
IBannerService.java 2KB
ProductSortAdminController.java 2KB
NumberUtil.java 2KB
ProductSort.java 2KB
CreateProductDTO.java 2KB
MemberController.java 2KB
Member.java 2KB
LiveOrderAdminController.java 2KB
YangApplication.java 2KB
ILiveShopCartService.java 2KB
MemberAdminController.java 1KB
IMemberService.java 1KB
ProductSortController.java 1KB
IProductSortService.java 1KB
LiveShopCartVO.java 1KB
LiveShopCart.java 1KB
ProductDetailVO.java 1KB
共 314 条
- 1
- 2
- 3
- 4
资源评论
lsx202406
- 粉丝: 2239
- 资源: 5546
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 技术资料分享Z-Stackapi函数非常好的技术资料.zip
- 技术资料分享Z-Stack-API-Chinese非常好的技术资料.zip
- 技术资料分享Z-Stack 开发指南非常好的技术资料.zip
- 技术资料分享Zigbee协议栈中文说明免费非常好的技术资料.zip
- 技术资料分享Zigbee协议栈及应用实现非常好的技术资料.zip
- 技术资料分享ZigBee协议栈的研究与实现非常好的技术资料.zip
- 技术资料分享ZigBee协议栈的分析与设计非常好的技术资料.zip
- 技术资料分享Zigbee协议栈OSAL层API函数(译)非常好的技术资料.zip
- 技术资料分享zigbee无信标网络设备的加入非常好的技术资料.zip
- 技术资料分享ZigBee问答之“KVP”、“MSG”非常好的技术资料.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功