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;
public class CorsConfig {
// 当前跨域请求最大有效时长。这里默认30天
private long maxAge = 30 * 24 * 60 * 60;
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址
......
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.linlinjava.litemall.core.util.ResponseUtil;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.MissingServletRequestParameterException;
......@@ -17,41 +18,43 @@ import javax.validation.ValidationException;
import java.util.Set;
@ControllerAdvice
@Order( value = Ordered.LOWEST_PRECEDENCE )
@Order
public class GlobalExceptionHandler {
private Log logger = LogFactory.getLog(GlobalExceptionHandler.class);
@ExceptionHandler(IllegalArgumentException.class)
@ResponseBody
public Object badArgumentHandler(IllegalArgumentException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue();
}
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
@ResponseBody
public Object badArgumentHandler(MethodArgumentTypeMismatchException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue();
}
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseBody
public Object badArgumentHandler(MissingServletRequestParameterException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue();
}
@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseBody
public Object badArgumentHandler(HttpMessageNotReadableException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return ResponseUtil.badArgumentValue();
}
@ExceptionHandler(ValidationException.class)
@ResponseBody
public Object badArgumentHandler(ValidationException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
if (e instanceof ConstraintViolationException) {
ConstraintViolationException exs = (ConstraintViolationException) e;
Set<ConstraintViolation<?>> violations = exs.getConstraintViolations();
......@@ -66,7 +69,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
@ResponseBody
public Object seriousHandler(Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return ResponseUtil.serious();
}
}
......@@ -29,13 +29,18 @@ public class JacksonConfig {
return new Jackson2ObjectMapperBuilderCustomizer() {
@Override
public void customize(Jackson2ObjectMapperBuilder builder) {
builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
builder.serializerByType(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
builder.serializerByType(LocalTime.class, new LocalTimeSerializer(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.serializerByType(LocalDateTime.class,
new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
builder.serializerByType(LocalDate.class,
new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
builder.serializerByType(LocalTime.class,
new LocalTimeSerializer(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.failOnUnknownProperties(false);
builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
......
package org.linlinjava.litemall.core.express;
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.dao.ExpressInfo;
import org.linlinjava.litemall.core.util.HttpUtil;
......@@ -13,10 +15,12 @@ import java.util.Map;
/**
* 物流查询服务
*
* <p>
* 快递鸟即时查询API http://www.kdniao.com/api-track
*/
public class ExpressService {
private final Log logger = LogFactory.getLog(ExpressService.class);
//请求url
private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
......@@ -59,7 +63,7 @@ public class ExpressService {
ei.setShipperName(getVendorName(expCode));
return ei;
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
......@@ -103,7 +107,7 @@ public class ExpressService {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes(charset));
byte[] result = md.digest();
StringBuffer sb = new StringBuffer(32);
StringBuilder sb = new StringBuilder(32);
for (int i = 0; i < result.length; i++) {
int val = result[i] & 0xff;
if (val <= 0xf) {
......@@ -126,12 +130,12 @@ public class ExpressService {
if (keyValue != null) {
content = content + keyValue;
}
byte[] src = new byte[0];
byte[] src;
try {
src = MD5(content, charset).getBytes(charset);
return Base64Utils.encodeToString(src);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
......
......@@ -35,7 +35,7 @@ public class TencentSmsSender implements SmsSender {
smsResult.setResult(result);
return smsResult;
} catch (HTTPException | IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
......@@ -52,7 +52,7 @@ public class TencentSmsSender implements SmsSender {
smsResult.setResult(result);
return smsResult;
} catch (HTTPException | IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
......
......@@ -47,7 +47,8 @@ public class WxTemplateSender {
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);
if (userFormid == null)
return;
......@@ -68,7 +69,7 @@ public class WxTemplateSender {
logger.warn("更新数据已失效");
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}
......
......@@ -2,6 +2,8 @@ package org.linlinjava.litemall.core.qcode;
import cn.binarywang.wx.miniapp.api.WxMaService;
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.system.SystemConfig;
import org.linlinjava.litemall.db.domain.LitemallGroupon;
......@@ -18,6 +20,7 @@ import java.net.URL;
@Service
public class QCodeService {
private final Log logger = LogFactory.getLog(QCodeService.class);
@Autowired
WxMaService wxMaService;
......@@ -28,21 +31,23 @@ public class QCodeService {
public String createGrouponShareImage(String goodName, String goodPicUrl, LitemallGroupon groupon) {
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);
//将商品图片,商品名字,商城名字画到模版图中
byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
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();
} catch (WxErrorException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
} catch (FileNotFoundException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return "";
......@@ -68,15 +73,16 @@ public class QCodeService {
byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName);
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();
} catch (WxErrorException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
} catch (FileNotFoundException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return "";
......@@ -126,7 +132,7 @@ public class QCodeService {
drawTextInImg(baseImage, goodName, 65, 867);
//写上商城名称
// drawTextInImgCenter(baseImage, shopName, 98);
// drawTextInImgCenter(baseImage, shopName, 98);
//转jpg
......@@ -173,7 +179,8 @@ public class QCodeService {
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();
g2D.drawImage(imageToWrite, x, y, width, heigth, null);
g2D.dispose();
......
......@@ -4,6 +4,8 @@ import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest;
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.UrlResource;
......@@ -20,6 +22,8 @@ import java.util.stream.Stream;
*/
public class AliyunStorage implements Storage {
private final Log logger = LogFactory.getLog(AliyunStorage.class);
private String endpoint;
private String accessKeyId;
private String accessKeySecret;
......@@ -84,7 +88,7 @@ public class AliyunStorage implements Storage {
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata);
PutObjectResult putObjectResult = getOSSClient().putObject(putObjectRequest);
} catch (Exception ex) {
ex.printStackTrace();
logger.error(ex.getMessage(), ex);
}
}
......@@ -110,7 +114,7 @@ public class AliyunStorage implements Storage {
return null;
}
} catch (MalformedURLException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return null;
}
}
......@@ -120,7 +124,7 @@ public class AliyunStorage implements Storage {
try {
getOSSClient().deleteObject(bucketName, keyName);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}
......
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.UrlResource;
......@@ -18,6 +20,9 @@ import java.util.stream.Stream;
*/
public class LocalStorage implements Storage {
private final Log logger = LogFactory.getLog(LocalStorage.class);
private String storagePath;
private String address;
......@@ -34,7 +39,7 @@ public class LocalStorage implements Storage {
try {
Files.createDirectories(rootLocation);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}
......@@ -83,7 +88,7 @@ public class LocalStorage implements Storage {
return null;
}
} catch (MalformedURLException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
return null;
}
}
......@@ -94,13 +99,13 @@ public class LocalStorage implements Storage {
try {
Files.delete(file);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}
@Override
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;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.UploadManager;
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.UrlResource;
......@@ -17,6 +18,8 @@ import java.util.stream.Stream;
public class QiniuStorage implements Storage {
private final Log logger = LogFactory.getLog(QiniuStorage.class);
private String endpoint;
private String accessKey;
private String secretKey;
......@@ -71,9 +74,9 @@ public class QiniuStorage implements Storage {
try {
String upToken = auth.uploadToken(bucketName);
Response response = uploadManager.put(inputStream, keyName, upToken, null, contentType);
uploadManager.put(inputStream, keyName, upToken, null, contentType);
} catch (QiniuException ex) {
ex.printStackTrace();
logger.error(ex.getMessage(), ex);
}
}
......@@ -94,13 +97,11 @@ public class QiniuStorage implements Storage {
Resource resource = new UrlResource(url);
if (resource.exists() || resource.isReadable()) {
return resource;
} else {
return null;
}
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
logger.error(e.getMessage(), e);
}
return null;
}
@Override
......@@ -111,11 +112,10 @@ public class QiniuStorage implements Storage {
}
bucketManager = new BucketManager(auth, new Configuration());
}
try {
bucketManager.delete(bucketName, keyName);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}
......
......@@ -6,8 +6,9 @@ import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.model.ObjectMetadata;
import com.qcloud.cos.model.PutObjectRequest;
import com.qcloud.cos.model.PutObjectResult;
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.UrlResource;
......@@ -22,6 +23,8 @@ import java.util.stream.Stream;
*/
public class TencentStorage implements Storage {
private final Log logger = LogFactory.getLog(TencentStorage.class);
private String secretId;
private String secretKey;
private String region;
......@@ -84,11 +87,12 @@ public class TencentStorage implements Storage {
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(contentLength);
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);
PutObjectResult putObjectResult = getCOSClient().putObject(putObjectRequest);
getCOSClient().putObject(putObjectRequest);
} catch (Exception ex) {
ex.printStackTrace();
logger.error(ex.getMessage(), ex);
}
}
......@@ -109,13 +113,11 @@ public class TencentStorage implements Storage {
Resource resource = new UrlResource(url);
if (resource.exists() || resource.isReadable()) {
return resource;
} else {
return null;
}
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
logger.error(e.getMessage(), e);
}
return null;
}
@Override
......@@ -123,7 +125,7 @@ public class TencentStorage implements Storage {
try {
getCOSClient().deleteObject(bucketName, keyName);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
}
......
......@@ -31,6 +31,7 @@ class SystemInistService {
private final static Map<String, String> DEFAULT_CONFIGS = new HashMap<>();
static {
// 小程序相关配置默认值
DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_WX_INDEX_NEW, "6");
......@@ -63,7 +64,7 @@ class SystemInistService {
// 2. 分析DEFAULT_CONFIGS
for (Map.Entry<String, String> entry : DEFAULT_CONFIGS.entrySet()) {
if(configs.containsKey(entry.getKey())){
if (configs.containsKey(entry.getKey())) {
continue;
}
......@@ -109,7 +110,9 @@ class SystemInistService {
infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 3, "系统设置");
infos.put("自动创建朋友圈分享图", Boolean.toString(SystemConfig.isAutoCreateShareImage()));
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;
}
......
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.IOException;
import java.io.InputStreamReader;
......@@ -14,6 +17,9 @@ import java.util.Map;
* @return 远程资源的响应结果
*/
public class HttpUtil {
private static final Log logger = LogFactory.getLog(HttpUtil.class);
/**
* 向指定 URL 发送POST方法的请求
*
......@@ -53,9 +59,9 @@ public class HttpUtil {
param.append(entry.getKey());
param.append("=");
param.append(entry.getValue());
//System.out.println(entry.getKey()+":"+entry.getValue());
}
//System.out.println("param:"+param.toString());
out.write(param.toString());
}
// flush输出流的缓冲
......@@ -68,7 +74,7 @@ public class HttpUtil {
result.append(line);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
//使用finally块来关闭输出流、输入流
finally {
......@@ -80,7 +86,7 @@ public class HttpUtil {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
logger.error(ex.getMessage(), ex);
}
}
return result.toString();
......
package org.linlinjava.litemall.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
......@@ -9,8 +12,10 @@ import java.net.UnknownHostException;
*/
public class IpUtil {
private static final Log logger = LogFactory.getLog(IpUtil.class);
public static String getIpAddr(HttpServletRequest request) {
String ipAddress = null;
String ipAddress;
try {
ipAddress = request.getHeader("x-forwarded-for");
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
......@@ -27,7 +32,7 @@ public class IpUtil {
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
ipAddress = inet.getHostAddress();
}
......@@ -42,7 +47,6 @@ public class IpUtil {
} catch (Exception e) {
ipAddress = "";
}
// ipAddress = this.getRequest().getRemoteAddr();
return ipAddress;
}
......
......@@ -3,22 +3,27 @@ package org.linlinjava.litemall.core.util;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import java.util.List;
import java.util.Map;
public class JacksonUtil {
private static final Log logger = LogFactory.getLog(JacksonUtil.class);
public static String parseString(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = null;
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
if (leaf != null)
return leaf.asText();
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
}
......@@ -26,7 +31,7 @@ public class JacksonUtil {
public static List<String> parseStringList(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = null;
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
......@@ -35,28 +40,28 @@ public class JacksonUtil {
return mapper.convertValue(leaf, new TypeReference<List<String>>() {
});
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
}
public static Integer parseInteger(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = null;
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
if (leaf != null)
return leaf.asInt();
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
}
public static List<Integer> parseIntegerList(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = null;
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
......@@ -65,7 +70,7 @@ public class JacksonUtil {
return mapper.convertValue(leaf, new TypeReference<List<Integer>>() {
});
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
}
......@@ -73,21 +78,21 @@ public class JacksonUtil {
public static Boolean parseBoolean(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = null;
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
if (leaf != null)
return leaf.asBoolean();
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
}
public static Short parseShort(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = null;
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
......@@ -96,14 +101,14 @@ public class JacksonUtil {
return value.shortValue();
}
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
}
public static Byte parseByte(String body, String field) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = null;
JsonNode node;
try {
node = mapper.readTree(body);
JsonNode leaf = node.get(field);
......@@ -112,20 +117,20 @@ public class JacksonUtil {
return value.byteValue();
}
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
}
public static <T> T parseObject(String body, String field, Class<T> clazz) {
ObjectMapper mapper = new ObjectMapper();
JsonNode node = null;
JsonNode node;
try {
node = mapper.readTree(body);
node = node.get(field);
return mapper.treeToValue(node, clazz);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
}
......@@ -136,10 +141,10 @@ public class JacksonUtil {
}
ObjectMapper mapper = new ObjectMapper();
try {
JsonNode jsonNode = mapper.readTree(json);
return jsonNode;
return mapper.readTree(json);
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
......@@ -148,9 +153,10 @@ public class JacksonUtil {
public static Map<String, String> toMap(String data) {
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.readValue(data, new TypeReference<Map<String, String>>(){});
return objectMapper.readValue(data, new TypeReference<Map<String, String>>() {
});
} catch (IOException e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
}
return null;
}
......
......@@ -9,7 +9,8 @@ import java.util.regex.Pattern;
/**
* 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/constant/RegexConstants.java
* https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/constant
* /RegexConstants.java
*/
public class RegexUtil {
......@@ -19,13 +20,15 @@ public class RegexUtil {
public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$";
/**
* 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 telecom: 133, 153, 173, 177, 180, 181, 189, 199</p>
* <p>global star: 1349</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.
*/
......@@ -37,7 +40,8 @@ public class RegexUtil {
/**
* 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.
*/
......@@ -60,7 +64,9 @@ public class RegexUtil {
/**
* 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.
*/
......@@ -255,7 +261,8 @@ public class RegexUtil {
* @return the list of input matches the regex
*/
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<>();
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input);
......@@ -273,7 +280,8 @@ public class RegexUtil {
* @return the array of strings computed by splitting input around matches of 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);
}
......@@ -291,7 +299,8 @@ public class RegexUtil {
public static String getReplaceFirst(final String input,
final String regex,
final String replacement) {
if (input == null) return "";
if (input == null)
return "";
return Pattern.compile(regex).matcher(input).replaceFirst(replacement);
}
......@@ -309,7 +318,8 @@ public class RegexUtil {
public static String getReplaceAll(final String input,
final String regex,
final String replacement) {
if (input == null) return "";
if (input == null)
return "";
return Pattern.compile(regex).matcher(input).replaceAll(replacement);
}
}
......@@ -65,8 +65,7 @@ public class ResponseUtil {
data.put("page", page.getPageNum());
data.put("limit", page.getPageSize());
data.put("pages", page.getPages());
}
else{
} else {
data.put("total", list.size());
data.put("page", 1);
data.put("limit", list.size());
......@@ -86,8 +85,7 @@ public class ResponseUtil {
data.put("page", page.getPageNum());
data.put("limit", page.getPageSize());
data.put("pages", page.getPages());
}
else{
} else {
data.put("total", pagedList.size());
data.put("page", 1);
data.put("limit", pagedList.size());
......
package org.linlinjava.litemall.core.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Map;
public class SystemInfoPrinter {
private static final Log logger = LogFactory.getLog(SystemInfoPrinter.class);
public static final String CREATE_PART_COPPER = "XOXOXOXOX";
private static int maxSize = 0;
......@@ -34,24 +39,24 @@ public class SystemInfoPrinter {
}
private static void printHeader(String title) {
System.out.println(getLineCopper());
System.out.println("");
System.out.println(" " + title);
System.out.println("");
logger.info(getLineCopper());
logger.info("");
logger.info(" " + title);
logger.info("");
}
private static void printEnd() {
System.out.println(" ");
System.out.println(getLineCopper());
logger.info(" ");
logger.info(getLineCopper());
}
private static String getLineCopper() {
String copper = "";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < maxSize; i++) {
copper += "=";
sb.append("=");
}
return copper;
return sb.toString();
}
private static void printLine(String head, String line) {
......@@ -59,11 +64,11 @@ public class SystemInfoPrinter {
return;
if (head.startsWith(CREATE_PART_COPPER)) {
System.out.println("");
System.out.println(" [[ " + line + " ]]");
System.out.println("");
logger.info("");
logger.info(" [[ " + line + " ]]");
logger.info("");
} else {
System.out.println(" " + head + " -> " + line);
logger.info(" " + head + " -> " + line);
}
}
}
package org.linlinjava.litemall.core.validator;
import com.google.common.collect.Lists;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList;
import java.util.List;
public class OrderValidator implements ConstraintValidator<Order, String> {
......@@ -10,7 +11,7 @@ public class OrderValidator implements ConstraintValidator<Order, String> {
@Override
public void initialize(Order order) {
valueList = new ArrayList<String>();
valueList = Lists.newArrayList();
for (String val : order.accepts()) {
valueList.add(val.toUpperCase());
}
......
package org.linlinjava.litemall.core.validator;
import com.google.common.collect.Lists;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList;
import java.util.List;
public class SortValidator implements ConstraintValidator<Sort, String> {
......@@ -10,7 +11,7 @@ public class SortValidator implements ConstraintValidator<Sort, String> {
@Override
public void initialize(Sort sort) {
valueList = new ArrayList<String>();
valueList = Lists.newArrayList();
for (String val : sort.accepts()) {
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