package com.utils;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.InetAddress;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author Administrator sk9TbyJ3y/ZNZdLyO1Oigg==
*/
public class Utils {
// public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException {
// System.out.println(encoderByMd5("abc"));
// System.out.println(encoderByMd5("1234"));
// }
public static String getUUID() {
//随机生成UUID
return UUID.randomUUID().toString().replace("-", "");
}
// public static String encoderByMd5(String str)
// throws NoSuchAlgorithmException, UnsupportedEncodingException {
// //确定计算方法
// MessageDigest md5 = MessageDigest.getInstance("MD5");
// BASE64Encoder base64en = new BASE64Encoder();
// //加密后的字符串
// String result = base64en.encode(md5.digest(str.getBytes("utf-8")));
// return result;
// }
/**
* 上传单个文件方法
* @param request
* @param file
* @return
* @throws IOException
*/
public static boolean uploadOneFileLayui(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws IOException {
if (!file.isEmpty()) { //如果文件不为空,写入上传路径
String path = request.getSession().getServletContext().getRealPath("/images/upload"); //上传文件路径
//文件原始名字
String filename = file.getOriginalFilename();
String suffixLast = filename.substring(filename.lastIndexOf(".")); //获取文件后缀
String newFileName = Utils.getUUID()+suffixLast; //文件新名字
File filepath = new File(path, newFileName);
////判断路径是否存在,如果不存在就创建一个
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
//将上传文件保存到一个目标文件当中
file.transferTo(new File(path + File.separator + newFileName));
InetAddress address= InetAddress.getByName(request.getServerName());
String ip = address.getHostAddress();//获取服务器IP地址
int port = request.getServerPort();//获取服务器端口
StringBuffer url = request.getRequestURL();//url全路径
String uri = request.getRequestURI();//相对路径
String relImage=new String(url).split(uri)[0];
//将图片路劲写在当前服务器ip请求端口下的路径
String imageUrl=relImage+"/images/upload/"+newFileName;
request.getSession().setAttribute("imageUploadUrl",imageUrl);
return true;
}
return false;
}
/**
* 上传单个文件--------------
* 上传到服务器具体的某个文件夹中
*
* @param request
* @param file
* @return
* @throws IOException
*/
public static boolean uploadOneFile(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws IOException {
if (!file.isEmpty()) { //如果文件不为空,写入上传路径
// String path = request.getSession().getServletContext().getRealPath("/images/upload"); //上传文件路径
// String path="/home/static/images/";//远程服务器路径
String path = null;
//文件原始名字localhost\\static\\images
String filename = file.getOriginalFilename();
String suffixLast = filename.substring(filename.lastIndexOf("."));
if (suffixLast.equals(".pdf")) {
//上传到pdf的文件夹中
path = "C:\\Users\\16941\\Desktop\\files\\pdf";
} else if (suffixLast.equals(".doc") || suffixLast.equals("docx")) {
//上传到word的文件夹中
} else if (suffixLast.equals(".mp3")) {
//上传到音频
} else if (suffixLast.equals(".mp4")) {
} else {
//上传到图片jpg||png
path = "C:\\Users\\16941\\Desktop\\files\\images\\";
}
// String suffixLast = filename.substring(filename.lastIndexOf(".")); //获取文件后缀
// String newFileName = Utils.getUUID()+suffixLast; //文件新名字
File filepath = new File(path, filename);
System.out.println("这是文件---" + filepath);
////判断路径是否存在,如果不存在就创建一个
if (!filepath.getParentFile().exists()) {
filepath.getParentFile().mkdirs();
}
//将上传文件保存到一个目标文件当中
file.transferTo(new File(path + File.separator + filepath.getName()));
InetAddress address = InetAddress.getByName(request.getServerName());
String ip = address.getHostAddress();//获取服务器IP地址
int port = request.getServerPort();//获取服务器端口
StringBuffer url = request.getRequestURL();//url全路径
String uri = request.getRequestURI();//相对路径
String relImage = new String(url).split(uri)[0];
//将图片路劲写在当前服务器ip请求端口下的路径
String imageUrl = path + filename;
request.getSession().setAttribute("imageUploadUrl", imageUrl);
return true;
}
return false;
}
public static boolean uploadOneFile2(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws IOException {
if (!file.isEmpty()) { //如果文件不为空,写入上传路径
File path2 = new File(ResourceUtils.getURL("classpath:static").getPath().replace("%20"," ").replace('/', '\\'));
System.out.println(path2);
System.out.println(path2.getAbsolutePath());
if(!path2.exists()) path2 = new File("");
//如果上传目录为/static/images/upload/,则可以如下获取:
File upload2 = new File(path2.getAbsolutePath(),"src/main/static/images");
String path333=upload2.getAbsolutePath();
//文件原始名字
String filename = file.getOriginalFilename();
String suffixLast = filename.substring(filename.lastIndexOf(".")); //获取文件后缀
String newFileName = Utils.getUUID()+suffixLast; //文件新名字
////判断路径是否存在,如果不存在就创建一个
if (!upload2.exists()) {
upload2.mkdirs();
}
//将上传文件保存到一个目标文件当中
file.transferTo(new File(path333 + File.separator + newFileName));
request.getSession().setAttribute("imageUploadUrl",path333+"/"+newFileName);
return true;
}
return false;
}
public static boolean springBootUploadOneFile(HttpServletRequest request, @RequestParam("file") MultipartFile file) throws IOException {
if (!file.isEmpty()) { //如果文件不为空,写入上传路径
//文件原始名字
String filename = file.getOriginalFilename();
// String suffixLast = filename.substring(filename.lastIndexOf(".")); //获取文件后缀
// String newFileName = Utils.getUUID()+suffixLast; //�
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
项目描述: 图书馆借阅系统是一个基于Java Web的毕业设计项目,采用SSM框架搭建,使用MySQL数据库存储数据,实现了图书馆的基本借阅管理功能。系统主要包括学生用户和系统管理员两个角色模块,分别具有不同的权限和功能。 系统管理员功能: 用户管理:管理员可以管理学生用户的注册信息,包括添加新用户、修改用户信息、删除用户等操作。 分类管理:管理员可以对图书进行分类管理,包括添加新分类、修改分类信息、删除分类等操作。 图书信息管理:管理员可以管理图书的基本信息,包括添加新图书、修改图书信息、删除图书等操作。 借阅记录管理:管理员可以查看学生的借阅记录,包括借阅时间、归还时间、逾期情况等信息。 图书出库管理:管理员可以管理图书的出库情况,包括添加出库记录、修改出库信息、删除出库记录等操作。 归还图书管理:管理员可以处理学生归还图书的请求,更新借阅记录信息。 学生用户功能: 注册登录:学生用户可以注册新账号并登录系统。 查看图书:学生用户可以浏览图书馆中的图书信息,包括图书名称、作者、分类等。 借阅图书:学生用户可以借阅图书,系统会记录借阅时间并更新借阅记录。 归还图书:学生可以..
资源推荐
资源详情
资源评论
收起资源包目录
基于Java Web的图书馆借阅系统毕业设计项目基于SSM框架MySQL数据库文件基于B/S (495个子文件)
Utils.class 12KB
Utils.class 12KB
CityController.class 6KB
CityController.class 6KB
StudentController.class 5KB
StudentController.class 5KB
BookCategoryController.class 5KB
BookCategoryController.class 5KB
BorrowController.class 4KB
BorrowController.class 4KB
AdminController.class 4KB
AdminController.class 4KB
CityDemo.class 3KB
CityDemo.class 3KB
BookInfo.class 3KB
BookInfo.class 3KB
Student.class 3KB
Student.class 3KB
ReqAndResData.class 3KB
ReqAndResData.class 3KB
BookInfoController.class 3KB
BookInfoController.class 3KB
Admin.class 3KB
Admin.class 3KB
LoginController.class 2KB
LoginController.class 2KB
LayuiRes.class 2KB
LayuiRes.class 2KB
Borrow.class 2KB
Borrow.class 2KB
CityDemoServiceImpl.class 2KB
CityDemoServiceImpl.class 2KB
StudentServiceImpl.class 1KB
StudentServiceImpl.class 1KB
AdminServiceImpl.class 1KB
AdminServiceImpl.class 1KB
BookCategoryServiceImpl.class 1KB
BookCategoryServiceImpl.class 1KB
BookCategory.class 1KB
BookCategory.class 1KB
BookInfoServiceImpl.class 1KB
BookInfoServiceImpl.class 1KB
BorrowServiceImpl.class 1KB
BorrowServiceImpl.class 1KB
StudentMapper.class 808B
StudentMapper.class 808B
BorrowMapper.class 796B
BorrowMapper.class 796B
AdminMapper.class 775B
AdminMapper.class 775B
TestController.class 724B
TestController.class 724B
BasicController.class 721B
BasicController.class 721B
CityDemoDao.class 708B
CityDemoDao.class 708B
BookInfoMapper.class 686B
BookInfoMapper.class 686B
BookCategoryMapper.class 685B
BookCategoryMapper.class 685B
CityDemoService.class 463B
CityDemoService.class 463B
BookCategoryService.class 319B
BookCategoryService.class 319B
BookInfoService.class 299B
StudentService.class 299B
BookInfoService.class 299B
StudentService.class 299B
BorrowService.class 295B
BorrowService.class 295B
AdminService.class 291B
AdminService.class 291B
layui.css 92KB
layui.css 92KB
layer.css 14KB
layer.css 14KB
layui.mobile.css 10KB
layui.mobile.css 10KB
laydate.css 7KB
laydate.css 7KB
code.css 1KB
code.css 1KB
iconfont.eot 40KB
iconfont.eot 40KB
59.gif 10KB
59.gif 10KB
22.gif 10KB
22.gif 10KB
24.gif 8KB
24.gif 8KB
13.gif 7KB
13.gif 7KB
16.gif 7KB
16.gif 7KB
39.gif 6KB
39.gif 6KB
64.gif 6KB
64.gif 6KB
63.gif 6KB
63.gif 6KB
共 495 条
- 1
- 2
- 3
- 4
- 5
资源评论
竹山全栈
- 粉丝: 2324
- 资源: 261
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功