Commit 4fec87a7 authored by sober's avatar sober Committed by linlinjava
Browse files

remove useless reference and modify log print type about core (#218)

parent b5d61aae
...@@ -10,6 +10,7 @@ import org.springframework.web.filter.CorsFilter; ...@@ -10,6 +10,7 @@ import org.springframework.web.filter.CorsFilter;
public class CorsConfig { public class CorsConfig {
// 当前跨域请求最大有效时长。这里默认30天 // 当前跨域请求最大有效时长。这里默认30天
private long maxAge = 30 * 24 * 60 * 60; private long maxAge = 30 * 24 * 60 * 60;
private CorsConfiguration buildConfig() { private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration(); CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址 corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址
......
package org.linlinjava.litemall.core.config; package org.linlinjava.litemall.core.config;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.validator.internal.engine.path.PathImpl; import org.hibernate.validator.internal.engine.path.PathImpl;
import org.linlinjava.litemall.core.util.ResponseUtil; import org.linlinjava.litemall.core.util.ResponseUtil;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MissingServletRequestParameterException; import org.springframework.web.bind.MissingServletRequestParameterException;
...@@ -17,41 +18,43 @@ import javax.validation.ValidationException; ...@@ -17,41 +18,43 @@ import javax.validation.ValidationException;
import java.util.Set; import java.util.Set;
@ControllerAdvice @ControllerAdvice
@Order( value = Ordered.LOWEST_PRECEDENCE ) @Order
public class GlobalExceptionHandler { public class GlobalExceptionHandler {
private Log logger = LogFactory.getLog(GlobalExceptionHandler.class);
@ExceptionHandler(IllegalArgumentException.class) @ExceptionHandler(IllegalArgumentException.class)
@ResponseBody @ResponseBody
public Object badArgumentHandler(IllegalArgumentException e) { public Object badArgumentHandler(IllegalArgumentException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
@ExceptionHandler(MethodArgumentTypeMismatchException.class) @ExceptionHandler(MethodArgumentTypeMismatchException.class)
@ResponseBody @ResponseBody
public Object badArgumentHandler(MethodArgumentTypeMismatchException e) { public Object badArgumentHandler(MethodArgumentTypeMismatchException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
@ExceptionHandler(MissingServletRequestParameterException.class) @ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseBody @ResponseBody
public Object badArgumentHandler(MissingServletRequestParameterException e) { public Object badArgumentHandler(MissingServletRequestParameterException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
@ExceptionHandler(HttpMessageNotReadableException.class) @ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseBody @ResponseBody
public Object badArgumentHandler(HttpMessageNotReadableException e) { public Object badArgumentHandler(HttpMessageNotReadableException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue(); return ResponseUtil.badArgumentValue();
} }
@ExceptionHandler(ValidationException.class) @ExceptionHandler(ValidationException.class)
@ResponseBody @ResponseBody
public Object badArgumentHandler(ValidationException e) { public Object badArgumentHandler(ValidationException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
if (e instanceof ConstraintViolationException) { if (e instanceof ConstraintViolationException) {
ConstraintViolationException exs = (ConstraintViolationException) e; ConstraintViolationException exs = (ConstraintViolationException) e;
Set<ConstraintViolation<?>> violations = exs.getConstraintViolations(); Set<ConstraintViolation<?>> violations = exs.getConstraintViolations();
...@@ -66,7 +69,7 @@ public class GlobalExceptionHandler { ...@@ -66,7 +69,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
@ResponseBody @ResponseBody
public Object seriousHandler(Exception e) { public Object seriousHandler(Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return ResponseUtil.serious(); return ResponseUtil.serious();
} }
} }
...@@ -29,13 +29,18 @@ public class JacksonConfig { ...@@ -29,13 +29,18 @@ public class JacksonConfig {
return new Jackson2ObjectMapperBuilderCustomizer() { return new Jackson2ObjectMapperBuilderCustomizer() {
@Override @Override
public void customize(Jackson2ObjectMapperBuilder builder) { public void customize(Jackson2ObjectMapperBuilder builder) {
builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); builder.serializerByType(LocalDateTime.class,
builder.serializerByType(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
builder.serializerByType(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss"))); builder.serializerByType(LocalDate.class,
new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); builder.serializerByType(LocalTime.class,
builder.deserializerByType(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
builder.deserializerByType(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss"))); builder.deserializerByType(LocalDateTime.class,
new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
builder.deserializerByType(LocalDate.class,
new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
builder.deserializerByType(LocalTime.class,
new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss")));
builder.serializationInclusion(JsonInclude.Include.NON_NULL); builder.serializationInclusion(JsonInclude.Include.NON_NULL);
builder.failOnUnknownProperties(false); builder.failOnUnknownProperties(false);
builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
......
package org.linlinjava.litemall.core.express; package org.linlinjava.litemall.core.express;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.express.config.ExpressProperties; import org.linlinjava.litemall.core.express.config.ExpressProperties;
import org.linlinjava.litemall.core.express.dao.ExpressInfo; import org.linlinjava.litemall.core.express.dao.ExpressInfo;
import org.linlinjava.litemall.core.util.HttpUtil; import org.linlinjava.litemall.core.util.HttpUtil;
...@@ -13,10 +15,12 @@ import java.util.Map; ...@@ -13,10 +15,12 @@ import java.util.Map;
/** /**
* 物流查询服务 * 物流查询服务
* * <p>
* 快递鸟即时查询API http://www.kdniao.com/api-track * 快递鸟即时查询API http://www.kdniao.com/api-track
*/ */
public class ExpressService { public class ExpressService {
private final Log logger = LogFactory.getLog(ExpressService.class);
//请求url //请求url
private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx"; private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
...@@ -59,7 +63,7 @@ public class ExpressService { ...@@ -59,7 +63,7 @@ public class ExpressService {
ei.setShipperName(getVendorName(expCode)); ei.setShipperName(getVendorName(expCode));
return ei; return ei;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
...@@ -103,7 +107,7 @@ public class ExpressService { ...@@ -103,7 +107,7 @@ public class ExpressService {
MessageDigest md = MessageDigest.getInstance("MD5"); MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes(charset)); md.update(str.getBytes(charset));
byte[] result = md.digest(); byte[] result = md.digest();
StringBuffer sb = new StringBuffer(32); StringBuilder sb = new StringBuilder(32);
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
int val = result[i] & 0xff; int val = result[i] & 0xff;
if (val <= 0xf) { if (val <= 0xf) {
...@@ -126,12 +130,12 @@ public class ExpressService { ...@@ -126,12 +130,12 @@ public class ExpressService {
if (keyValue != null) { if (keyValue != null) {
content = content + keyValue; content = content + keyValue;
} }
byte[] src = new byte[0]; byte[] src;
try { try {
src = MD5(content, charset).getBytes(charset); src = MD5(content, charset).getBytes(charset);
return Base64Utils.encodeToString(src); return Base64Utils.encodeToString(src);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
......
...@@ -35,7 +35,7 @@ public class TencentSmsSender implements SmsSender { ...@@ -35,7 +35,7 @@ public class TencentSmsSender implements SmsSender {
smsResult.setResult(result); smsResult.setResult(result);
return smsResult; return smsResult;
} catch (HTTPException | IOException e) { } catch (HTTPException | IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
...@@ -52,7 +52,7 @@ public class TencentSmsSender implements SmsSender { ...@@ -52,7 +52,7 @@ public class TencentSmsSender implements SmsSender {
smsResult.setResult(result); smsResult.setResult(result);
return smsResult; return smsResult;
} catch (HTTPException | IOException e) { } catch (HTTPException | IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
......
...@@ -47,7 +47,8 @@ public class WxTemplateSender { ...@@ -47,7 +47,8 @@ public class WxTemplateSender {
sendMsg(touser, templatId, parms, page, "", ""); sendMsg(touser, templatId, parms, page, "", "");
} }
private void sendMsg(String touser, String templatId, String[] parms, String page, String color, String emphasisKeyword) { private void sendMsg(String touser, String templatId, String[] parms, String page, String color,
String emphasisKeyword) {
LitemallUserFormid userFormid = formIdService.queryByOpenId(touser); LitemallUserFormid userFormid = formIdService.queryByOpenId(touser);
if (userFormid == null) if (userFormid == null)
return; return;
...@@ -68,7 +69,7 @@ public class WxTemplateSender { ...@@ -68,7 +69,7 @@ public class WxTemplateSender {
logger.warn("更新数据已失效"); logger.warn("更新数据已失效");
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
......
...@@ -2,6 +2,8 @@ package org.linlinjava.litemall.core.qcode; ...@@ -2,6 +2,8 @@ package org.linlinjava.litemall.core.qcode;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.core.storage.StorageService; import org.linlinjava.litemall.core.storage.StorageService;
import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.core.system.SystemConfig;
import org.linlinjava.litemall.db.domain.LitemallGroupon; import org.linlinjava.litemall.db.domain.LitemallGroupon;
...@@ -18,6 +20,7 @@ import java.net.URL; ...@@ -18,6 +20,7 @@ import java.net.URL;
@Service @Service
public class QCodeService { public class QCodeService {
private final Log logger = LogFactory.getLog(QCodeService.class);
@Autowired @Autowired
WxMaService wxMaService; WxMaService wxMaService;
...@@ -28,21 +31,23 @@ public class QCodeService { ...@@ -28,21 +31,23 @@ public class QCodeService {
public String createGrouponShareImage(String goodName, String goodPicUrl, LitemallGroupon groupon) { public String createGrouponShareImage(String goodName, String goodPicUrl, LitemallGroupon groupon) {
try { try {
//创建该商品的二维码 //创建该商品的二维码
File file = wxMaService.getQrcodeService().createWxaCodeUnlimit("groupon," + groupon.getId(), "pages/index/index"); File file = wxMaService.getQrcodeService().createWxaCodeUnlimit("groupon," + groupon.getId(), "pages" +
"/index/index");
FileInputStream inputStream = new FileInputStream(file); FileInputStream inputStream = new FileInputStream(file);
//将商品图片,商品名字,商城名字画到模版图中 //将商品图片,商品名字,商城名字画到模版图中
byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName); byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData); ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData);
//存储分享图 //存储分享图
LitemallStorage storageInfo = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(groupon.getId().toString())); LitemallStorage storageInfo = storageService.store(inputStream2, imageData.length, "image/jpeg",
getKeyName(groupon.getId().toString()));
return storageInfo.getUrl(); return storageInfo.getUrl();
} catch (WxErrorException e) { } catch (WxErrorException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return ""; return "";
...@@ -68,15 +73,16 @@ public class QCodeService { ...@@ -68,15 +73,16 @@ public class QCodeService {
byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName); byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData); ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData);
//存储分享图 //存储分享图
LitemallStorage litemallStorage = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(goodId)); LitemallStorage litemallStorage = storageService.store(inputStream2, imageData.length, "image/jpeg",
getKeyName(goodId));
return litemallStorage.getUrl(); return litemallStorage.getUrl();
} catch (WxErrorException e) { } catch (WxErrorException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return ""; return "";
...@@ -126,7 +132,7 @@ public class QCodeService { ...@@ -126,7 +132,7 @@ public class QCodeService {
drawTextInImg(baseImage, goodName, 65, 867); drawTextInImg(baseImage, goodName, 65, 867);
//写上商城名称 //写上商城名称
// drawTextInImgCenter(baseImage, shopName, 98); // drawTextInImgCenter(baseImage, shopName, 98);
//转jpg //转jpg
...@@ -173,7 +179,8 @@ public class QCodeService { ...@@ -173,7 +179,8 @@ public class QCodeService {
g2D.dispose(); g2D.dispose();
} }
private void drawImgInImg(BufferedImage baseImage, BufferedImage imageToWrite, int x, int y, int width, int heigth) { private void drawImgInImg(BufferedImage baseImage, BufferedImage imageToWrite, int x, int y, int width,
int heigth) {
Graphics2D g2D = (Graphics2D) baseImage.getGraphics(); Graphics2D g2D = (Graphics2D) baseImage.getGraphics();
g2D.drawImage(imageToWrite, x, y, width, heigth, null); g2D.drawImage(imageToWrite, x, y, width, heigth, null);
g2D.dispose(); g2D.dispose();
......
...@@ -4,6 +4,8 @@ import com.aliyun.oss.OSSClient; ...@@ -4,6 +4,8 @@ import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata; import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest; import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult; import com.aliyun.oss.model.PutObjectResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
...@@ -20,6 +22,8 @@ import java.util.stream.Stream; ...@@ -20,6 +22,8 @@ import java.util.stream.Stream;
*/ */
public class AliyunStorage implements Storage { public class AliyunStorage implements Storage {
private final Log logger = LogFactory.getLog(AliyunStorage.class);
private String endpoint; private String endpoint;
private String accessKeyId; private String accessKeyId;
private String accessKeySecret; private String accessKeySecret;
...@@ -84,7 +88,7 @@ public class AliyunStorage implements Storage { ...@@ -84,7 +88,7 @@ public class AliyunStorage implements Storage {
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata); PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata);
PutObjectResult putObjectResult = getOSSClient().putObject(putObjectRequest); PutObjectResult putObjectResult = getOSSClient().putObject(putObjectRequest);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
} }
} }
...@@ -110,7 +114,7 @@ public class AliyunStorage implements Storage { ...@@ -110,7 +114,7 @@ public class AliyunStorage implements Storage {
return null; return null;
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null; return null;
} }
} }
...@@ -120,7 +124,7 @@ public class AliyunStorage implements Storage { ...@@ -120,7 +124,7 @@ public class AliyunStorage implements Storage {
try { try {
getOSSClient().deleteObject(bucketName, keyName); getOSSClient().deleteObject(bucketName, keyName);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
......
package org.linlinjava.litemall.core.storage; package org.linlinjava.litemall.core.storage;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
...@@ -18,6 +20,9 @@ import java.util.stream.Stream; ...@@ -18,6 +20,9 @@ import java.util.stream.Stream;
*/ */
public class LocalStorage implements Storage { public class LocalStorage implements Storage {
private final Log logger = LogFactory.getLog(LocalStorage.class);
private String storagePath; private String storagePath;
private String address; private String address;
...@@ -34,7 +39,7 @@ public class LocalStorage implements Storage { ...@@ -34,7 +39,7 @@ public class LocalStorage implements Storage {
try { try {
Files.createDirectories(rootLocation); Files.createDirectories(rootLocation);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
...@@ -83,7 +88,7 @@ public class LocalStorage implements Storage { ...@@ -83,7 +88,7 @@ public class LocalStorage implements Storage {
return null; return null;
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null; return null;
} }
} }
...@@ -94,13 +99,13 @@ public class LocalStorage implements Storage { ...@@ -94,13 +99,13 @@ public class LocalStorage implements Storage {
try { try {
Files.delete(file); Files.delete(file);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
@Override @Override
public String generateUrl(String keyName) { public String generateUrl(String keyName) {
String url = address + keyName;
return url; return address + keyName;
} }
} }
\ No newline at end of file
package org.linlinjava.litemall.core.storage; package org.linlinjava.litemall.core.storage;
import com.qiniu.common.QiniuException; import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager; import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration; import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager; import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth; import com.qiniu.util.Auth;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
...@@ -17,6 +18,8 @@ import java.util.stream.Stream; ...@@ -17,6 +18,8 @@ import java.util.stream.Stream;
public class QiniuStorage implements Storage { public class QiniuStorage implements Storage {
private final Log logger = LogFactory.getLog(QiniuStorage.class);
private String endpoint; private String endpoint;
private String accessKey; private String accessKey;
private String secretKey; private String secretKey;
...@@ -71,9 +74,9 @@ public class QiniuStorage implements Storage { ...@@ -71,9 +74,9 @@ public class QiniuStorage implements Storage {
try { try {
String upToken = auth.uploadToken(bucketName); String upToken = auth.uploadToken(bucketName);
Response response = uploadManager.put(inputStream, keyName, upToken, null, contentType); uploadManager.put(inputStream, keyName, upToken, null, contentType);
} catch (QiniuException ex) { } catch (QiniuException ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
} }
} }
...@@ -94,13 +97,11 @@ public class QiniuStorage implements Storage { ...@@ -94,13 +97,11 @@ public class QiniuStorage implements Storage {
Resource resource = new UrlResource(url); Resource resource = new UrlResource(url);
if (resource.exists() || resource.isReadable()) { if (resource.exists() || resource.isReadable()) {
return resource; return resource;
} else {
return null;
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null;
} }
return null;
} }
@Override @Override
...@@ -111,11 +112,10 @@ public class QiniuStorage implements Storage { ...@@ -111,11 +112,10 @@ public class QiniuStorage implements Storage {
} }
bucketManager = new BucketManager(auth, new Configuration()); bucketManager = new BucketManager(auth, new Configuration());
} }
try { try {
bucketManager.delete(bucketName, keyName); bucketManager.delete(bucketName, keyName);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
......
...@@ -6,8 +6,9 @@ import com.qcloud.cos.auth.BasicCOSCredentials; ...@@ -6,8 +6,9 @@ import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials; import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.model.ObjectMetadata; import com.qcloud.cos.model.ObjectMetadata;
import com.qcloud.cos.model.PutObjectRequest; import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
import com.qcloud.cos.region.Region; import com.qcloud.cos.region.Region;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource; import org.springframework.core.io.UrlResource;
...@@ -22,6 +23,8 @@ import java.util.stream.Stream; ...@@ -22,6 +23,8 @@ import java.util.stream.Stream;
*/ */
public class TencentStorage implements Storage { public class TencentStorage implements Storage {
private final Log logger = LogFactory.getLog(TencentStorage.class);
private String secretId; private String secretId;
private String secretKey; private String secretKey;
private String region; private String region;
...@@ -84,11 +87,12 @@ public class TencentStorage implements Storage { ...@@ -84,11 +87,12 @@ public class TencentStorage implements Storage {
ObjectMetadata objectMetadata = new ObjectMetadata(); ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(contentLength); objectMetadata.setContentLength(contentLength);
objectMetadata.setContentType(contentType); objectMetadata.setContentType(contentType);
// 对象键(Key)是对象在存储桶中的唯一标识。例如,在对象的访问域名 `bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg` 中,对象键为 doc1/pic1.jpg, 详情参考 [对象键](https://cloud.tencent.com/document/product/436/13324) // 对象键(Key)是对象在存储桶中的唯一标识。例如,在对象的访问域名 `bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg`
// 中,对象键为 doc1/pic1.jpg, 详情参考 [对象键](https://cloud.tencent.com/document/product/436/13324)
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata); PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata);
PutObjectResult putObjectResult = getCOSClient().putObject(putObjectRequest); getCOSClient().putObject(putObjectRequest);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
} }
} }
...@@ -109,13 +113,11 @@ public class TencentStorage implements Storage { ...@@ -109,13 +113,11 @@ public class TencentStorage implements Storage {
Resource resource = new UrlResource(url); Resource resource = new UrlResource(url);
if (resource.exists() || resource.isReadable()) { if (resource.exists() || resource.isReadable()) {
return resource; return resource;
} else {
return null;
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
return null;
} }
return null;
} }
@Override @Override
...@@ -123,7 +125,7 @@ public class TencentStorage implements Storage { ...@@ -123,7 +125,7 @@ public class TencentStorage implements Storage {
try { try {
getCOSClient().deleteObject(bucketName, keyName); getCOSClient().deleteObject(bucketName, keyName);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
} }
......
...@@ -31,6 +31,7 @@ class SystemInistService { ...@@ -31,6 +31,7 @@ class SystemInistService {
private final static Map<String, String> DEFAULT_CONFIGS = new HashMap<>(); private final static Map<String, String> DEFAULT_CONFIGS = new HashMap<>();
static { static {
// 小程序相关配置默认值 // 小程序相关配置默认值
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_WX_INDEX_NEW, "6"); DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_WX_INDEX_NEW, "6");
...@@ -63,7 +64,7 @@ class SystemInistService { ...@@ -63,7 +64,7 @@ class SystemInistService {
// 2. 分析DEFAULT_CONFIGS // 2. 分析DEFAULT_CONFIGS
for (Map.Entry<String, String> entry : DEFAULT_CONFIGS.entrySet()) { for (Map.Entry<String, String> entry : DEFAULT_CONFIGS.entrySet()) {
if(configs.containsKey(entry.getKey())){ if (configs.containsKey(entry.getKey())) {
continue; continue;
} }
...@@ -109,7 +110,9 @@ class SystemInistService { ...@@ -109,7 +110,9 @@ class SystemInistService {
infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 3, "系统设置"); infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 3, "系统设置");
infos.put("自动创建朋友圈分享图", Boolean.toString(SystemConfig.isAutoCreateShareImage())); infos.put("自动创建朋友圈分享图", Boolean.toString(SystemConfig.isAutoCreateShareImage()));
infos.put("商场名称", SystemConfig.getMallName()); infos.put("商场名称", SystemConfig.getMallName());
infos.put("首页显示记录数:NEW,HOT,BRAND,TOPIC,CatlogList,CatlogMore", SystemConfig.getNewLimit() + "," + SystemConfig.getHotLimit() + "," + SystemConfig.getBrandLimit() + "," + SystemConfig.getTopicLimit() + "," + SystemConfig.getCatlogListLimit() + "," + SystemConfig.getCatlogMoreLimit()); infos.put("首页显示记录数:NEW,HOT,BRAND,TOPIC,CatlogList,CatlogMore",
SystemConfig.getNewLimit() + "," + SystemConfig.getHotLimit() + "," + SystemConfig.getBrandLimit() +
"," + SystemConfig.getTopicLimit() + "," + SystemConfig.getCatlogListLimit() + "," + SystemConfig.getCatlogMoreLimit());
return infos; return infos;
} }
......
package org.linlinjava.litemall.core.util; package org.linlinjava.litemall.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
...@@ -14,6 +17,9 @@ import java.util.Map; ...@@ -14,6 +17,9 @@ import java.util.Map;
* @return 远程资源的响应结果 * @return 远程资源的响应结果
*/ */
public class HttpUtil { public class HttpUtil {
private static final Log logger = LogFactory.getLog(HttpUtil.class);
/** /**
* 向指定 URL 发送POST方法的请求 * 向指定 URL 发送POST方法的请求
* *
...@@ -53,9 +59,9 @@ public class HttpUtil { ...@@ -53,9 +59,9 @@ public class HttpUtil {
param.append(entry.getKey()); param.append(entry.getKey());
param.append("="); param.append("=");
param.append(entry.getValue()); param.append(entry.getValue());
//System.out.println(entry.getKey()+":"+entry.getValue());
} }
//System.out.println("param:"+param.toString());
out.write(param.toString()); out.write(param.toString());
} }
// flush输出流的缓冲 // flush输出流的缓冲
...@@ -68,7 +74,7 @@ public class HttpUtil { ...@@ -68,7 +74,7 @@ public class HttpUtil {
result.append(line); result.append(line);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
//使用finally块来关闭输出流、输入流 //使用finally块来关闭输出流、输入流
finally { finally {
...@@ -80,7 +86,7 @@ public class HttpUtil { ...@@ -80,7 +86,7 @@ public class HttpUtil {
in.close(); in.close();
} }
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); logger.error(ex.getMessage(), ex);
} }
} }
return result.toString(); return result.toString();
......
package org.linlinjava.litemall.core.util; package org.linlinjava.litemall.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
...@@ -9,8 +12,10 @@ import java.net.UnknownHostException; ...@@ -9,8 +12,10 @@ import java.net.UnknownHostException;
*/ */
public class IpUtil { public class IpUtil {
private static final Log logger = LogFactory.getLog(IpUtil.class);
public static String getIpAddr(HttpServletRequest request) { public static String getIpAddr(HttpServletRequest request) {
String ipAddress = null; String ipAddress;
try { try {
ipAddress = request.getHeader("x-forwarded-for"); ipAddress = request.getHeader("x-forwarded-for");
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
...@@ -27,7 +32,7 @@ public class IpUtil { ...@@ -27,7 +32,7 @@ public class IpUtil {
try { try {
inet = InetAddress.getLocalHost(); inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) { } catch (UnknownHostException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
ipAddress = inet.getHostAddress(); ipAddress = inet.getHostAddress();
} }
...@@ -42,7 +47,6 @@ public class IpUtil { ...@@ -42,7 +47,6 @@ public class IpUtil {
} catch (Exception e) { } catch (Exception e) {
ipAddress = ""; ipAddress = "";
} }
// ipAddress = this.getRequest().getRemoteAddr();
return ipAddress; return ipAddress;
} }
......
...@@ -3,22 +3,27 @@ package org.linlinjava.litemall.core.util; ...@@ -3,22 +3,27 @@ package org.linlinjava.litemall.core.util;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class JacksonUtil { public class JacksonUtil {
private static final Log logger = LogFactory.getLog(JacksonUtil.class);
public static String parseString(String body, String field) { public static String parseString(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
if (leaf != null) if (leaf != null)
return leaf.asText(); return leaf.asText();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
...@@ -26,7 +31,7 @@ public class JacksonUtil { ...@@ -26,7 +31,7 @@ public class JacksonUtil {
public static List<String> parseStringList(String body, String field) { public static List<String> parseStringList(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
...@@ -35,28 +40,28 @@ public class JacksonUtil { ...@@ -35,28 +40,28 @@ public class JacksonUtil {
return mapper.convertValue(leaf, new TypeReference<List<String>>() { return mapper.convertValue(leaf, new TypeReference<List<String>>() {
}); });
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
public static Integer parseInteger(String body, String field) { public static Integer parseInteger(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
if (leaf != null) if (leaf != null)
return leaf.asInt(); return leaf.asInt();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
public static List<Integer> parseIntegerList(String body, String field) { public static List<Integer> parseIntegerList(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
...@@ -65,7 +70,7 @@ public class JacksonUtil { ...@@ -65,7 +70,7 @@ public class JacksonUtil {
return mapper.convertValue(leaf, new TypeReference<List<Integer>>() { return mapper.convertValue(leaf, new TypeReference<List<Integer>>() {
}); });
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
...@@ -73,21 +78,21 @@ public class JacksonUtil { ...@@ -73,21 +78,21 @@ public class JacksonUtil {
public static Boolean parseBoolean(String body, String field) { public static Boolean parseBoolean(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
if (leaf != null) if (leaf != null)
return leaf.asBoolean(); return leaf.asBoolean();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
public static Short parseShort(String body, String field) { public static Short parseShort(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
...@@ -96,14 +101,14 @@ public class JacksonUtil { ...@@ -96,14 +101,14 @@ public class JacksonUtil {
return value.shortValue(); return value.shortValue();
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
public static Byte parseByte(String body, String field) { public static Byte parseByte(String body, String field) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
JsonNode leaf = node.get(field); JsonNode leaf = node.get(field);
...@@ -112,20 +117,20 @@ public class JacksonUtil { ...@@ -112,20 +117,20 @@ public class JacksonUtil {
return value.byteValue(); return value.byteValue();
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
public static <T> T parseObject(String body, String field, Class<T> clazz) { public static <T> T parseObject(String body, String field, Class<T> clazz) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode node = null; JsonNode node;
try { try {
node = mapper.readTree(body); node = mapper.readTree(body);
node = node.get(field); node = node.get(field);
return mapper.treeToValue(node, clazz); return mapper.treeToValue(node, clazz);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
...@@ -136,10 +141,10 @@ public class JacksonUtil { ...@@ -136,10 +141,10 @@ public class JacksonUtil {
} }
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
try { try {
JsonNode jsonNode = mapper.readTree(json);
return jsonNode; return mapper.readTree(json);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
...@@ -148,9 +153,10 @@ public class JacksonUtil { ...@@ -148,9 +153,10 @@ public class JacksonUtil {
public static Map<String, String> toMap(String data) { public static Map<String, String> toMap(String data) {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
try { try {
return objectMapper.readValue(data, new TypeReference<Map<String, String>>(){}); return objectMapper.readValue(data, new TypeReference<Map<String, String>>() {
});
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error(e.getMessage(), e);
} }
return null; return null;
} }
......
...@@ -9,7 +9,8 @@ import java.util.regex.Pattern; ...@@ -9,7 +9,8 @@ import java.util.regex.Pattern;
/** /**
* RegexUtil类的代码是来自[AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode)的RegexUtils类和RegexConstants类 * RegexUtil类的代码是来自[AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode)的RegexUtils类和RegexConstants类
* https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/util/RegexUtils.java * https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/util/RegexUtils.java
* https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/constant/RegexConstants.java * https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/constant
* /RegexConstants.java
*/ */
public class RegexUtil { public class RegexUtil {
...@@ -19,13 +20,15 @@ public class RegexUtil { ...@@ -19,13 +20,15 @@ public class RegexUtil {
public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$"; public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$";
/** /**
* Regex of exact mobile. * Regex of exact mobile.
* <p>china mobile: 134(0-8), 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 178, 182, 183, 184, 187, 188, 198</p> * <p>china mobile: 134(0-8), 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 178, 182, 183, 184,
* 187, 188, 198</p>
* <p>china unicom: 130, 131, 132, 145, 155, 156, 166, 171, 175, 176, 185, 186</p> * <p>china unicom: 130, 131, 132, 145, 155, 156, 166, 171, 175, 176, 185, 186</p>
* <p>china telecom: 133, 153, 173, 177, 180, 181, 189, 199</p> * <p>china telecom: 133, 153, 173, 177, 180, 181, 189, 199</p>
* <p>global star: 1349</p> * <p>global star: 1349</p>
* <p>virtual operator: 170</p> * <p>virtual operator: 170</p>
*/ */
public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(16[6])|(17[0,1,3,5-8])|(18[0-9])|(19[8,9]))\\d{8}$"; public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(16[6])|(17[0,1,3,5-8])|" +
"(18[0-9])|(19[8,9]))\\d{8}$";
/** /**
* Regex of telephone number. * Regex of telephone number.
*/ */
...@@ -37,7 +40,8 @@ public class RegexUtil { ...@@ -37,7 +40,8 @@ public class RegexUtil {
/** /**
* Regex of id card number which length is 18. * Regex of id card number which length is 18.
*/ */
public static final String REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$"; public static final String REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}" +
"([0-9Xx])$";
/** /**
* Regex of email. * Regex of email.
*/ */
...@@ -60,7 +64,9 @@ public class RegexUtil { ...@@ -60,7 +64,9 @@ public class RegexUtil {
/** /**
* Regex of date which pattern is "yyyy-MM-dd". * Regex of date which pattern is "yyyy-MM-dd".
*/ */
public static final String REGEX_DATE = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$"; public static final String REGEX_DATE = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|" +
"(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|" +
"(?:0[48]|[2468][048]|[13579][26])00)-02-29)$";
/** /**
* Regex of ip address. * Regex of ip address.
*/ */
...@@ -255,7 +261,8 @@ public class RegexUtil { ...@@ -255,7 +261,8 @@ public class RegexUtil {
* @return the list of input matches the regex * @return the list of input matches the regex
*/ */
public static List<String> getMatches(final String regex, final CharSequence input) { public static List<String> getMatches(final String regex, final CharSequence input) {
if (input == null) return Collections.emptyList(); if (input == null)
return Collections.emptyList();
List<String> matches = new ArrayList<>(); List<String> matches = new ArrayList<>();
Pattern pattern = Pattern.compile(regex); Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input); Matcher matcher = pattern.matcher(input);
...@@ -273,7 +280,8 @@ public class RegexUtil { ...@@ -273,7 +280,8 @@ public class RegexUtil {
* @return the array of strings computed by splitting input around matches of regex * @return the array of strings computed by splitting input around matches of regex
*/ */
public static String[] getSplits(final String input, final String regex) { public static String[] getSplits(final String input, final String regex) {
if (input == null) return new String[0]; if (input == null)
return new String[0];
return input.split(regex); return input.split(regex);
} }
...@@ -291,7 +299,8 @@ public class RegexUtil { ...@@ -291,7 +299,8 @@ public class RegexUtil {
public static String getReplaceFirst(final String input, public static String getReplaceFirst(final String input,
final String regex, final String regex,
final String replacement) { final String replacement) {
if (input == null) return ""; if (input == null)
return "";
return Pattern.compile(regex).matcher(input).replaceFirst(replacement); return Pattern.compile(regex).matcher(input).replaceFirst(replacement);
} }
...@@ -309,7 +318,8 @@ public class RegexUtil { ...@@ -309,7 +318,8 @@ public class RegexUtil {
public static String getReplaceAll(final String input, public static String getReplaceAll(final String input,
final String regex, final String regex,
final String replacement) { final String replacement) {
if (input == null) return ""; if (input == null)
return "";
return Pattern.compile(regex).matcher(input).replaceAll(replacement); return Pattern.compile(regex).matcher(input).replaceAll(replacement);
} }
} }
...@@ -65,8 +65,7 @@ public class ResponseUtil { ...@@ -65,8 +65,7 @@ public class ResponseUtil {
data.put("page", page.getPageNum()); data.put("page", page.getPageNum());
data.put("limit", page.getPageSize()); data.put("limit", page.getPageSize());
data.put("pages", page.getPages()); data.put("pages", page.getPages());
} } else {
else{
data.put("total", list.size()); data.put("total", list.size());
data.put("page", 1); data.put("page", 1);
data.put("limit", list.size()); data.put("limit", list.size());
...@@ -86,8 +85,7 @@ public class ResponseUtil { ...@@ -86,8 +85,7 @@ public class ResponseUtil {
data.put("page", page.getPageNum()); data.put("page", page.getPageNum());
data.put("limit", page.getPageSize()); data.put("limit", page.getPageSize());
data.put("pages", page.getPages()); data.put("pages", page.getPages());
} } else {
else{
data.put("total", pagedList.size()); data.put("total", pagedList.size());
data.put("page", 1); data.put("page", 1);
data.put("limit", pagedList.size()); data.put("limit", pagedList.size());
......
package org.linlinjava.litemall.core.util; package org.linlinjava.litemall.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Map; import java.util.Map;
public class SystemInfoPrinter { public class SystemInfoPrinter {
private static final Log logger = LogFactory.getLog(SystemInfoPrinter.class);
public static final String CREATE_PART_COPPER = "XOXOXOXOX"; public static final String CREATE_PART_COPPER = "XOXOXOXOX";
private static int maxSize = 0; private static int maxSize = 0;
...@@ -34,24 +39,24 @@ public class SystemInfoPrinter { ...@@ -34,24 +39,24 @@ public class SystemInfoPrinter {
} }
private static void printHeader(String title) { private static void printHeader(String title) {
System.out.println(getLineCopper()); logger.info(getLineCopper());
System.out.println(""); logger.info("");
System.out.println(" " + title); logger.info(" " + title);
System.out.println(""); logger.info("");
} }
private static void printEnd() { private static void printEnd() {
System.out.println(" "); logger.info(" ");
System.out.println(getLineCopper()); logger.info(getLineCopper());
} }
private static String getLineCopper() { private static String getLineCopper() {
String copper = ""; StringBuilder sb = new StringBuilder();
for (int i = 0; i < maxSize; i++) { for (int i = 0; i < maxSize; i++) {
copper += "="; sb.append("=");
} }
return copper; return sb.toString();
} }
private static void printLine(String head, String line) { private static void printLine(String head, String line) {
...@@ -59,11 +64,11 @@ public class SystemInfoPrinter { ...@@ -59,11 +64,11 @@ public class SystemInfoPrinter {
return; return;
if (head.startsWith(CREATE_PART_COPPER)) { if (head.startsWith(CREATE_PART_COPPER)) {
System.out.println(""); logger.info("");
System.out.println(" [[ " + line + " ]]"); logger.info(" [[ " + line + " ]]");
System.out.println(""); logger.info("");
} else { } else {
System.out.println(" " + head + " -> " + line); logger.info(" " + head + " -> " + line);
} }
} }
} }
package org.linlinjava.litemall.core.validator; package org.linlinjava.litemall.core.validator;
import com.google.common.collect.Lists;
import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext; import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class OrderValidator implements ConstraintValidator<Order, String> { public class OrderValidator implements ConstraintValidator<Order, String> {
...@@ -10,7 +11,7 @@ public class OrderValidator implements ConstraintValidator<Order, String> { ...@@ -10,7 +11,7 @@ public class OrderValidator implements ConstraintValidator<Order, String> {
@Override @Override
public void initialize(Order order) { public void initialize(Order order) {
valueList = new ArrayList<String>(); valueList = Lists.newArrayList();
for (String val : order.accepts()) { for (String val : order.accepts()) {
valueList.add(val.toUpperCase()); valueList.add(val.toUpperCase());
} }
......
package org.linlinjava.litemall.core.validator; package org.linlinjava.litemall.core.validator;
import com.google.common.collect.Lists;
import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext; import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public class SortValidator implements ConstraintValidator<Sort, String> { public class SortValidator implements ConstraintValidator<Sort, String> {
...@@ -10,7 +11,7 @@ public class SortValidator implements ConstraintValidator<Sort, String> { ...@@ -10,7 +11,7 @@ public class SortValidator implements ConstraintValidator<Sort, String> {
@Override @Override
public void initialize(Sort sort) { public void initialize(Sort sort) {
valueList = new ArrayList<String>(); valueList = Lists.newArrayList();
for (String val : sort.accepts()) { for (String val : sort.accepts()) {
valueList.add(val.toUpperCase()); valueList.add(val.toUpperCase());
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment