This commit is contained in:
xiangwb
2017-11-20 15:35:21 +08:00
parent 91350a2274
commit 472ccea7ee
5 changed files with 26 additions and 34 deletions
@@ -1,6 +1,5 @@
package com.xwbing.util;
import com.xwbing.exception.BusinessException;
import java.text.DecimalFormat;
@@ -17,8 +16,8 @@ import java.util.*;
* 说明: 日期处理类
*/
public class DateUtil2 {
public static DecimalFormat df = new DecimalFormat("######0.00");
public static final long SECOND = 1000;
public static DecimalFormat df = new DecimalFormat("#");
public static final long MINUTE = SECOND * 60;
public static final long HOUR = MINUTE * 60;
public static final long DAY = HOUR * 24;
@@ -41,7 +40,7 @@ public class DateUtil2 {
* @param pattern
* @return
*/
private static DateTimeFormatter getDateFormat(String pattern) {
public static DateTimeFormatter getDateFormat(String pattern) {
return DateTimeFormatter.ofPattern(pattern);
}
@@ -137,7 +136,8 @@ public class DateUtil2 {
/////////////////////////////获取数据////////////获取数据/////////////////////////////////////////////////////////////
/**
*获取周几
* 获取周几
*
* @param day 0代表当天 负数代表前几天 正数代表后几天
* @return
*/
@@ -198,12 +198,11 @@ public class DateUtil2 {
* @return
*/
public static String dateAddMinusDays(String date, int day) {
LocalDate localDate = LocalDate.parse(date, getDateFormat(YYYY_MM_DD));
LocalDate localDate = LocalDate.parse(date);
LocalDate newDate = day >= 0 ? localDate.plusDays(day) : localDate.minusDays(Math.abs(day));
return newDate.toString();
}
/**
* 获取当月的第一天
*
@@ -212,7 +211,7 @@ public class DateUtil2 {
public static String firstDayOfMonth() {
LocalDate localDate = LocalDate.now();
LocalDate date = localDate.with(TemporalAdjusters.firstDayOfMonth());
return date.format(getDateFormat(YYYY_MM_DD));
return date.toString();
}
/**
@@ -223,7 +222,7 @@ public class DateUtil2 {
public static String firstDayOfLastMonth() {
LocalDate localDate = LocalDate.now();
LocalDate date = localDate.minusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
return date.format(getDateFormat(YYYY_MM_DD));
return date.toString();
}
/**
@@ -234,7 +233,7 @@ public class DateUtil2 {
public static String firstDayOfNextMonth() {
LocalDate localDate = LocalDate.now();
LocalDate date = localDate.plusMonths(1).with(TemporalAdjusters.firstDayOfMonth());
return date.format(getDateFormat(YYYY_MM_DD));
return date.toString();
}
/**
@@ -245,7 +244,7 @@ public class DateUtil2 {
*/
public static String getMonthFirstDay(int month) {
LocalDate localDate = LocalDate.now().withMonth(month).with(TemporalAdjusters.firstDayOfMonth());
return localDate.format(getDateFormat(YYYY_MM_DD));
return localDate.toString();
}
/**
@@ -256,7 +255,7 @@ public class DateUtil2 {
public static String firstDayOfYear() {
LocalDate localDate = LocalDate.now();
LocalDate date = localDate.with(TemporalAdjusters.firstDayOfYear());
return date.format(getDateFormat(YYYY_MM_DD));
return date.toString();
}
/**
@@ -268,7 +267,7 @@ public class DateUtil2 {
public static String getYearFirstDay(int year) {
LocalDate localDate = LocalDate.now();
LocalDate date = localDate.withYear(year).with(TemporalAdjusters.firstDayOfYear());
return date.format(getDateFormat(YYYY_MM_DD));
return date.toString();
}
/**
@@ -352,8 +351,8 @@ public class DateUtil2 {
* @return
*/
public static String hoursBetween2(String startDateTime, String endDateTime) {
LocalDateTime sDateTime = LocalDateTime.parse(startDateTime);
LocalDateTime eDateTime = LocalDateTime.parse(endDateTime);
LocalDateTime sDateTime = LocalDateTime.parse(startDateTime, getDateFormat(YYYY_MM_DD_HH_MM));
LocalDateTime eDateTime = LocalDateTime.parse(endDateTime, getDateFormat(YYYY_MM_DD_HH_MM));
Duration duration = Duration.between(sDateTime, eDateTime);
long m = duration.toMinutes();
return df.format(m / 60.0);
@@ -16,7 +16,6 @@ import javax.servlet.Filter;
* 作者: xiangwb
*/
@Configuration//相当于.xml文件中的<beans></beans>
//@ComponentScan(value = {"com.xwbing"}, excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)})
//@Import(xxx.class)//用来导入其他配置类
//@ImportResource("classpath:applicationContext.xml")//用来加载其他xml配置文件
public class ApplicationContextConfig {
@@ -2,8 +2,6 @@ package com.xwbing.configuration;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import com.xwbing.handler.LoginInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
@@ -22,12 +20,9 @@ import java.util.List;
* 创建时间: 2017/5/10 16:36
* 作者: xiangwb
*/
@Configuration
@EnableWebMvc
//@ComponentScan(basePackages = {"com.xwbing.controller"}, includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = RestController.class)})
@Configuration
public class DispatcherServletConfig extends WebMvcConfigurerAdapter {
private final Logger logger = LoggerFactory.getLogger(DispatcherServletConfig.class);
/***
* 添加拦截器
* @param registry
@@ -44,7 +39,9 @@ public class DispatcherServletConfig extends WebMvcConfigurerAdapter {
/**
* 配置静态访问资源
* 访问时不需要前缀
* 默认:优先级
* /**映射到
* classpath:/META-INF/resources
* classpath:/resources
* classpath:/static
@@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
@@ -95,16 +94,4 @@ public class TestControl {
RestMessage restMessage = qrCodeZipService.batchGetImage(response, names, fileName);
return JSONObjResult.toJSONObj(restMessage);
}
@GetMapping("test")
public JSONObject test() throws IOException {
RestMessage restMessage = new RestMessage();
String path = qrCodeZipService.getPath();
File file = new File(path + File.separator + "demo.txt");//创建文件对象,并不创建文件
if (!file.exists()) {
file.createNewFile(); //创建文件
}
return JSONObjResult.toJSONObj(restMessage);
}
}
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Welcome to the world</title>
</head>
<body>
<h2>Hello World!</h2>
</body>
</html>