1.开发框架:SpringMVC+ SpringBoot+Spring Security+Spring Data JPA+JWT+Hiberate
2.代码管理工具:git
3.仓库管理了工具:maven
4.接口测试界面:swagger
5.数据库:测试接口阶段:h2数据库;后期集成阶段:Mysql数据库
6.开发工具:ideal 【安装lombok(注解getter/setter等)、SonarLint(代码检查工具)、Alibaba Java Coding Guidelines(阿里编码规约)】
遇见问题:①编写导入文件实现类没有返回值,导致无论是导入成功还是失败前端测试都为通过,这是编写大忌;
②日期格式的转换,在excel导入时日期为data类型,即: EEE MMM dd HH:mm:ss zzz yyyy的格式
③假期名、开始日期和结束日期的约束没有做自定义的异常抛出
④对结束日期没有对截止时间约束
⑤重复导入数据不覆盖,多条重复
问题解决:①使用Boolean布尔类型返回值,数据导入并写入数据库返回true, 数据导入失败返回false,在controller做自定义异常抛出,不允许直接报错;
②使用日期格式转换类SimpleDateFormat sfStart = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", java.util.Locale.ENGLISH); 将object类型的数据转换为String 类型,再有parse方法转成data类型封装到实体类
③在对非空属性转换data类型前做判断,空则报异常
④使用日历类Calendar now = Calendar.getInstance(); 对结束日期做约束,截止加上23:59:59
now.setTime(sfStart.parse(String.valueOf(next[3])));
now.set(Calendar.HOUR_OF_DAY, 23);
now.set(Calendar.MINUTE, 59);
now.set(Calendar.SECOND, 59);
⑤开始日期时间永远小于结束时间,否则抛异常;对导入的日期(开始—结束)范围做一次遍历查询,如出现相同情况则删除数据库内容,否则重新插入;
遇见问题:①获取resource目录下的文件失败
解决问题:①获取resource目录下文件classpath:template/fileName
public static void download(HttpServletRequest request, HttpServletResponse response,
String downLoadPath, String storeName
, String downloadName) throws Exception {
request.setCharacterEncoding("UTF-8");
//获取下载文件路径
downLoadPath = "classpath:template" + File.separator + storeName;
File file = ResourceUtils.getFile(downLoadPath);
if (!file.exists()) {
throw new DownloadFileNotFoundException();
}
//获取文件的长度
long fileLength = file.length();
// 下载文件名,为空则表示和服务器文件名一样
if (downloadName == null || "".equals(downloadName)) {
downloadName = URLEncoder.encode(storeName, "UTF-8");
} else {
downloadName = URLEncoder.encode(downloadName, "UTF-8");
}
//设置文件输出类型
response.setCharacterEncoding("utf-8");
response.setContentType("application/octet-stream");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Access-Control-Allow-Origin", "*");
String userAgent = request.getHeader("User-Agent").toLowerCase();
if (userAgent.contains(BROWSER_TYPE_FIREFOX)) {
//火狐浏览器
response.setHeader("Content-Disposition", "attachment;filename=\"" + downloadName + "\"");
} else {
response.setHeader("Content-Disposition", "attachment;filename*=UTF-8''" + downloadName);
}
//设置输出长度
response.setHeader("Content-Length", String.valueOf(fileLength));
//获取输入流
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
//输出流
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
bos.flush();
//关闭流
bis.close();
bos.close();
}