基于javaweb+mysql的ssm+maven电影在线观看系统(java+ssm+jsp+layui+maven+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SSM+Maven电影在线观看系统(java+ssm+jsp+layui+maven+mysql)
一、项目简述
环境配置:
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
项目技术:
JSP +Spring + SpringMVC + MyBatis + html+ css + JavaScript + JQuery + Ajax + layui+ maven等等。
return videoServiceImpl.delAll(id);
}
@RequestMapping("video/update")
@ResponseBody
public Map<String,Object> update(HttpServletRequest request, MultipartFile file,Integer id
, String name, @RequestParam(value = "type",required = false) Integer type2
, @RequestParam(value = "category",required = false) List<Integer> category
, String starring, Integer year, String location,Integer statue
,String description,Integer totalEpisode,Integer currentEpisode){
int result;
if (file != null){
String filename = file.getOriginalFilename(); //获取文件名
String suffix = filename.substring(filename.lastIndexOf("."));
String src = request.getServletContext().getRealPath("file/video/images/");
File dest = new File(src+ "/" + name + suffix);
String imgPath = "file/video/images/" + name+suffix;
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),dest);
} catch (IOException e) {
e.printStackTrace();
}
result = videoServiceImpl.updVideo(id,name,totalEpisode,currentEpisode,imgPath,type2,category,starring,year,location,statue,description);
}else{
result = videoServiceImpl.updVideo(id,name,totalEpisode,currentEpisode,null,type2,category,starring,year,location,statue,description);
}
Map<String,Object> map = new HashMap<>();
if (result == 1){
map.put("code",1);
}else{
map.put("code",0);
}
return map;
}
@RequestMapping("video/updateForForm")
public String updateForForm(HttpServletRequest request, MultipartFile file,Integer id
, String name, @RequestParam(value = "type",required = false) Integer type2
, @RequestParam(value = "category",required = false) List<Integer> category
, String starring, Integer year, String location,Integer statue
,String description,Integer totalEpisode,Integer currentEpisode){
if (file != null){
Object[] objs = CodeImageUtil.createImage();
String code = (String) objs[0];
BufferedImage image = (BufferedImage) objs[1];
OutputStream os = response.getOutputStream();
ImageIO.write(image,"png",os);
session.setAttribute("adminLoginCode",code);
}
@RequestMapping(value = "login",produces = "text/html;charset=UTF-8;")
@ResponseBody
public String login(Admin admin, String code, HttpServletRequest request, HttpSession session){
String sessionCode = (String) session.getAttribute("adminLoginCode");
JSONObject obj = new JSONObject();
if(!sessionCode.toLowerCase().equals(code.toLowerCase())){ //验证码输入错误
obj.put("loginMsg","验证码输入错误!");
obj.put("loginCode",0);
return obj.toString();
}
Admin adminByName = managerServiceImpl.selByName(admin.getName());
if(adminByName == null){ //用户名不存在
obj.put("loginMsg","用户名不存在!");
obj.put("loginCode",0);
return obj.toString();
}
Admin adminByNameAndPassword = managerServiceImpl.selByNameAndPassword(admin.getName(),admin.getPassword());
if (adminByNameAndPassword == null){ //密码错误
obj.put("loginMsg","密码错误!");
obj.put("loginCode",0);
return obj.toString();
}
session.setAttribute("admin",adminByNameAndPassword);
obj.put("loginMsg","登陆成功!");
obj.put("loginCode",1);
return obj.toString();
}
@RequestMapping("toIndex")
public String toIndex(){
return "redirect:/jsp/manage/index.jsp";
}
@RequestMapping(value = "getAll",produces="text/html;charset=utf-8")
@ResponseBody
public String getAll(int page,int limit){
int start = (page-1)*limit;
List<User> userList = userServiceImpl.getAll(start, limit);
int count = userServiceImpl.getCount();
JSONObject jsonObject = new JSONObject();
public Map<String,Object> checkChunk(HttpServletRequest req,String fileMd5,int chunk,String chunkSize){
File checkFile = new File(req.getServletContext().getRealPath("file/video/videos/") + "/" + fileMd5 + "/" + chunk);
Map<String,Object> map = new HashMap<>();
//检查文件大小是否一致
if (checkFile.exists() && checkFile.length() == Integer.parseInt(chunkSize)){
map.put("ifExist",1);
}else {
map.put("ifExist",0);
}
return map;
}
/**
* 合并分片
* @param fileName
* @param fileMd5
* @return
*/
@RequestMapping(value = "video/detail/mergeChunks",produces="text/html;charset=utf-8")
@ResponseBody
public String mergeChunks(HttpServletRequest req, String fileName,String fileMd5){
String ServerPath = req.getServletContext().getRealPath("file/video/videos/");
//找到路径中所有的分片文件
File f = new File(ServerPath + "/" + fileMd5);
File[] fileArray = f.listFiles(new FileFilter() {
@Override
public boolean accept(File src) {
//只筛选文件
if (src.isDirectory()){
return false;
}
return true;
}
});
//转成集合,便于排序
List<File> fileList = new ArrayList<File>(Arrays.asList(fileArray));
//从小到大排序
fileList.sort(new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
if (Integer.parseInt(o1.getName()) < Integer.parseInt(o2.getName())) {
return -1;
}
return 1;
}
});
File outputFile = new File(ServerPath + "/" + fileName);
// public void upload(HttpServletRequest req, MultipartFile file,String fileMd5,String chunk){
// File dir = new File(req.getServletContext().getRealPath("file/video/videos/"));
// File chunkFile = new File(dir + "/" + file.getOriginalFilename());
// try {
// FileUtils.copyInputStreamToFile(file.getInputStream(),chunkFile);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
/**
* webUploader分块上传单个文件
* @param file
* @return
*/
@RequestMapping("video/detail/upload")
@ResponseBody
public void upload(HttpServletRequest req, MultipartFile file,String fileMd5,String chunk){
File dir = new File(req.getServletContext().getRealPath("file/video/videos/") +"/"+ fileMd5);
if (!dir.exists()){
dir.mkdir();
}
File chunkFile = new File(dir + "/" + chunk);
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),chunkFile);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 断点续传,检查分片是否以上传
* @param chunk
* @param chunkSize
* @return
*/
@RequestMapping("video/detail/checkChunk")
@ResponseBody
public Map<String,Object> checkChunk(HttpServletRequest req,String fileMd5,int chunk,String chunkSize){
File checkFile = new File(req.getServletContext().getRealPath("file/video/videos/") + "/" + fileMd5 + "/" + chunk);
Map<String,Object> map = new HashMap<>();
//检查文件大小是否一致
if (checkFile.exists() && checkFile.length() == Integer.parseInt(chunkSize)){
map.put("ifExist",1);
//img.delete();
}
}
List<VideoDetail> details = videoServiceImpl.getDetailById(id);
videoServiceImpl.delDetail(id);
for (VideoDetail detail : details){
if (detail.getFileName() != null && !detail.getFileName().equals("")){
File videoPath = new File(req.getServletContext().getRealPath("file/video/videos/"+detail.getFileName()));
System.out.println(videoPath);
if (videoPath.exists()){
//videoPath.delete();
}
}
}
return videoServiceImpl.delAll(id);
}
@RequestMapping("video/update")
@ResponseBody
public Map<String,Object> update(HttpServletRequest request, MultipartFile file,Integer id
, String name, @RequestParam(value = "type",required = false) Integer type2
, @RequestParam(value = "category",required = false) List<Integer> category
, String starring, Integer year, String location,Integer statue
,String description,Integer totalEpisode,Integer currentEpisode){
int result;
if (file != null){
String filename = file.getOriginalFilename(); //获取文件名
String suffix = filename.substring(filename.lastIndexOf("."));
String src = request.getServletContext().getRealPath("file/video/images/");
File dest = new File(src+ "/" + name + suffix);
String imgPath = "file/video/images/" + name+suffix;
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),dest);
} catch (IOException e) {
e.printStackTrace();
}
result = videoServiceImpl.updVideo(id,name,totalEpisode,currentEpisode,imgPath,type2,category,starring,year,location,statue,description);
}else{
result = videoServiceImpl.updVideo(id,name,totalEpisode,currentEpisode,null,type2,category,starring,year,location,statue,description);
return userServiceImpl.delById(id);
}
@RequestMapping("video/list")
public String video(HttpServletRequest request){
List<Video> videos = videoServiceImpl.getAllVideos();
List<Category> type = categoryServiceImpl.selByPid(0);
request.setAttribute("videos",videos);
request.setAttribute("type",type);
return "manage/videolist";
}
@RequestMapping("video/getCategoryByPid/{pid}")
@ResponseBody
public List<Category> getCategoryByPid(@PathVariable("pid") int pid){
return categoryServiceImpl.selByPid(pid);
}
@RequestMapping("video/search")
public String search(HttpServletRequest request,Video video,String year){
System.out.println(video);
List<Video> videos = videoServiceImpl.getAllVideosByCondition(video,year);
List<Category> types = categoryServiceImpl.selByPid(0);
request.setAttribute("videos",videos);
request.setAttribute("type",types);
request.setAttribute("video",video);
request.setAttribute("year",year);
return "manage/videolist";
}
@RequestMapping("video/add")
@ResponseBody
public Map<String,Object> add(HttpServletRequest request, MultipartFile file
, String name, @RequestParam(value = "type",required = false) Integer type2
, @RequestParam(value = "category",required = false) List<Integer> category
, String starring, Integer year, String location,Integer statue
,String description,Integer totalEpisode,Integer currentEpisode){
String filename = file.getOriginalFilename(); //获取文件名
String suffix = filename.substring(filename.lastIndexOf("."));
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),chunkFile);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 断点续传,检查分片是否以上传
* @param chunk
* @param chunkSize
* @return
*/
@RequestMapping("video/detail/checkChunk")
@ResponseBody
public Map<String,Object> checkChunk(HttpServletRequest req,String fileMd5,int chunk,String chunkSize){
File checkFile = new File(req.getServletContext().getRealPath("file/video/videos/") + "/" + fileMd5 + "/" + chunk);
Map<String,Object> map = new HashMap<>();
//检查文件大小是否一致
if (checkFile.exists() && checkFile.length() == Integer.parseInt(chunkSize)){
map.put("ifExist",1);
}else {
map.put("ifExist",0);
}
return map;
}
/**
* 合并分片
* @param fileName
* @param fileMd5
* @return
*/
@RequestMapping(value = "video/detail/mergeChunks",produces="text/html;charset=utf-8")
@ResponseBody
public String mergeChunks(HttpServletRequest req, String fileName,String fileMd5){
String ServerPath = req.getServletContext().getRealPath("file/video/videos/");
//找到路径中所有的分片文件
File f = new File(ServerPath + "/" + fileMd5);
File[] fileArray = f.listFiles(new FileFilter() {
@Override
public boolean accept(File src) {
// * @param file
// * @return
// */
// @RequestMapping("video/detail/upload")
// @ResponseBody
// public void upload(HttpServletRequest req, MultipartFile file,String fileMd5,String chunk){
// File dir = new File(req.getServletContext().getRealPath("file/video/videos/"));
// File chunkFile = new File(dir + "/" + file.getOriginalFilename());
// try {
// FileUtils.copyInputStreamToFile(file.getInputStream(),chunkFile);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
/**
* webUploader分块上传单个文件
* @param file
* @return
*/
@RequestMapping("video/detail/upload")
@ResponseBody
public void upload(HttpServletRequest req, MultipartFile file,String fileMd5,String chunk){
File dir = new File(req.getServletContext().getRealPath("file/video/videos/") +"/"+ fileMd5);
if (!dir.exists()){
dir.mkdir();
}
File chunkFile = new File(dir + "/" + chunk);
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),chunkFile);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 断点续传,检查分片是否以上传
* @param chunk
* @param chunkSize
* @return
return "manage/video_detail";
}
@RequestMapping("video/detail/addVideoDetail/{id}")
@ResponseBody
public Map<String,Object> addVideoDetail(HttpServletRequest request,@PathVariable("id")int id,String title,int episode){
int result = videoServiceImpl.insVideoDetail(id,title,episode);
Map<String,Object> map = new HashMap<>();
if (result == 1){
map.put("code",1);
}else{
map.put("code",0);
}
return map;
}
// /**
// * webUploader上传单个文件
// * @param file
// * @return
// */
// @RequestMapping("video/detail/upload")
// @ResponseBody
// public void upload(HttpServletRequest req, MultipartFile file,String fileMd5,String chunk){
// File dir = new File(req.getServletContext().getRealPath("file/video/videos/"));
// File chunkFile = new File(dir + "/" + file.getOriginalFilename());
// try {
// FileUtils.copyInputStreamToFile(file.getInputStream(),chunkFile);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
/**
* webUploader分块上传单个文件
* @param file
* @return
*/
@RequestMapping("video/detail/upload")
@ResponseBody
public void upload(HttpServletRequest req, MultipartFile file,String fileMd5,String chunk){
File dir = new File(req.getServletContext().getRealPath("file/video/videos/") +"/"+ fileMd5);
if (!dir.exists()){
dir.mkdir();
}
File chunkFile = new File(dir + "/" + chunk);
try {
/**
* webUploader分块上传单个文件
* @param file
* @return
*/
@RequestMapping("video/detail/upload")
@ResponseBody
public void upload(HttpServletRequest req, MultipartFile file,String fileMd5,String chunk){
File dir = new File(req.getServletContext().getRealPath("file/video/videos/") +"/"+ fileMd5);
if (!dir.exists()){
dir.mkdir();
}
File chunkFile = new File(dir + "/" + chunk);
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),chunkFile);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 断点续传,检查分片是否以上传
* @param chunk
* @param chunkSize
* @return
*/
@RequestMapping("video/detail/checkChunk")
@ResponseBody
public Map<String,Object> checkChunk(HttpServletRequest req,String fileMd5,int chunk,String chunkSize){
File checkFile = new File(req.getServletContext().getRealPath("file/video/videos/") + "/" + fileMd5 + "/" + chunk);
Map<String,Object> map = new HashMap<>();
//检查文件大小是否一致
if (checkFile.exists() && checkFile.length() == Integer.parseInt(chunkSize)){
map.put("ifExist",1);
}else {
map.put("ifExist",0);
}
return map;
}
/**
* 合并分片
* @param fileName
* @param fileMd5
* @return
*/
@RequestMapping(value = "video/detail/mergeChunks",produces="text/html;charset=utf-8")
@ResponseBody
public String mergeChunks(HttpServletRequest req, String fileName,String fileMd5){
String ServerPath = req.getServletContext().getRealPath("file/video/videos/");
@Controller
@RequestMapping("user")
public class UserController {
@Resource
private UserService userServiceImpl;
@Resource
private HistoryService historyServiceImpl;
@RequestMapping(value = "getAll",produces="text/html;charset=utf-8")
@ResponseBody
public String getAll(int page,int limit){
int start = (page-1)*limit;
List<User> userList = userServiceImpl.getAll(start, limit);
int count = userServiceImpl.getCount();
JSONObject jsonObject = new JSONObject();
jsonObject.put("fileName",uuid+suffix);
return jsonObject.toString();
} catch (IOException e) {
System.out.println("图片上传失败");
jsonObject.put("code",0);
return jsonObject.toString();
}
}
@RequestMapping(value = "imageUpdate",produces="text/html;charset=utf-8")
@ResponseBody
public String imageUpdate(MultipartFile file,HttpSession session,HttpServletRequest request){
User user = (User) session.getAttribute("user");
JSONObject jsonObject = new JSONObject();
File oldFile = new File(request.getServletContext().getRealPath(user.getImg()));
System.out.println(oldFile);
if (oldFile.exists()){
// if (oldFile.delete()){
// System.out.println("删除成功");
// }
}
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
String fileName = user.getUsername()+ "-" + new Date().getTime()+suffix;
String src = request.getServletContext().getRealPath("file/user/avatar/" + fileName);
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),new File(src));
userServiceImpl.updImgById(user.getId(),"file/user/avatar/" + fileName);
user.setImg("file/user/avatar/" + fileName);
session.setAttribute("user",user);
jsonObject.put("src","file/user/avatar/" + fileName);
jsonObject.put("code",1);
} catch (IOException e) {
System.out.println("图片上传失败");
jsonObject.put("code",0);
return jsonObject.toString();
}
return jsonObject.toString();
}
@RequestMapping("update")
public String update(User user,HttpSession session,HttpServletRequest req){
System.out.println(user);
userServiceImpl.updByUser(user);
User oldUser = (User) session.getAttribute("user");
user.setImg(oldUser.getImg());
session.setAttribute("user",user);
List<Video> collections = userServiceImpl.getCollection(user.getId());
req.setAttribute("collections",collections);
return "/user/home";
}
return map;
}
// /**
// * webUploader上传单个文件
// * @param file
// * @return
// */
// @RequestMapping("video/detail/upload")
// @ResponseBody
// public void upload(HttpServletRequest req, MultipartFile file,String fileMd5,String chunk){
// File dir = new File(req.getServletContext().getRealPath("file/video/videos/"));
// File chunkFile = new File(dir + "/" + file.getOriginalFilename());
// try {
// FileUtils.copyInputStreamToFile(file.getInputStream(),chunkFile);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
/**
* webUploader分块上传单个文件
* @param file
* @return
*/
@RequestMapping("video/detail/upload")
@ResponseBody
public void upload(HttpServletRequest req, MultipartFile file,String fileMd5,String chunk){
File dir = new File(req.getServletContext().getRealPath("file/video/videos/") +"/"+ fileMd5);
if (!dir.exists()){
dir.mkdir();
}
File chunkFile = new File(dir + "/" + chunk);
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),chunkFile);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 断点续传,检查分片是否以上传
* @param chunk
* @param chunkSize
* @return
*/
@RequestMapping("video/detail/checkChunk")
@ResponseBody
public Map<String,Object> checkChunk(HttpServletRequest req,String fileMd5,int chunk,String chunkSize){
File checkFile = new File(req.getServletContext().getRealPath("file/video/videos/") + "/" + fileMd5 + "/" + chunk);
Map<String,Object> map = new HashMap<>();
//检查文件大小是否一致
if (checkFile.exists() && checkFile.length() == Integer.parseInt(chunkSize)){
map.put("ifExist",1);
jsonObject.put("data",userList);
return jsonObject.toString();
}
@RequestMapping("user/list")
public String user(){
return "manage/userlist";
}
@RequestMapping("user/detail/{id}")
public String userDetail(@PathVariable("id")int id, HttpServletRequest request){
User user = userServiceImpl.getUserById(id);
request.setAttribute("user",user);
return "manage/user_detail";
}
@RequestMapping("user/delete/{id}")
@ResponseBody
public int userDelete(@PathVariable("id")int id, HttpServletRequest request){
return userServiceImpl.delById(id);
}
@RequestMapping("video/list")
public String video(HttpServletRequest request){
List<Video> videos = videoServiceImpl.getAllVideos();
List<Category> type = categoryServiceImpl.selByPid(0);
request.setAttribute("videos",videos);
request.setAttribute("type",type);
return "manage/videolist";
}
@RequestMapping("video/getCategoryByPid/{pid}")
@ResponseBody
public List<Category> getCategoryByPid(@PathVariable("pid") int pid){
return categoryServiceImpl.selByPid(pid);
}
@RequestMapping("video/search")
public String search(HttpServletRequest request,Video video,String year){
System.out.println(video);
List<Video> videos = videoServiceImpl.getAllVideosByCondition(video,year);
List<Category> types = categoryServiceImpl.selByPid(0);
request.setAttribute("videos",videos);
request.setAttribute("type",types);
request.setAttribute("video",video);
request.setAttribute("year",year);
return "manage/videolist";
}
@RequestMapping("video/add")
@ResponseBody
public Map<String,Object> add(HttpServletRequest request, MultipartFile file
, String name, @RequestParam(value = "type",required = false) Integer type2
, @RequestParam(value = "category",required = false) List<Integer> category
@RequestMapping("video/add")
@ResponseBody
public Map<String,Object> add(HttpServletRequest request, MultipartFile file
, String name, @RequestParam(value = "type",required = false) Integer type2
, @RequestParam(value = "category",required = false) List<Integer> category
, String starring, Integer year, String location,Integer statue
,String description,Integer totalEpisode,Integer currentEpisode){
String filename = file.getOriginalFilename(); //获取文件名
String suffix = filename.substring(filename.lastIndexOf("."));
String src = request.getServletContext().getRealPath("file/video/images/");
File dest = new File(src+ "/" + name + suffix);
String imgPath = "file/video/images/" + name+suffix;
Map<String,Object> map = new HashMap<>();
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),dest);
map.put("code",1);
} catch (IOException e) {
map.put("code",0);
e.printStackTrace();
}
videoServiceImpl.insVideo(name,totalEpisode,currentEpisode,imgPath,type2,category,starring,year,location,statue,description);
return map;
}
@RequestMapping("video/getVideoById")
@ResponseBody
public Video getVideoById(Integer id){
return videoServiceImpl.getVideoWithCategory(id);
}
@RequestMapping("video/del")
@ResponseBody
public int delAll(Integer id,HttpServletRequest req){
Video video = videoServiceImpl.getById(id);
String imgPath = req.getServletContext().getRealPath(video.getImgSrc());
if (imgPath != null && !imgPath.equals("")){
File img = new File(imgPath);
System.out.println(img);
if (img.exists()){
//img.delete();
}
}
List<VideoDetail> details = videoServiceImpl.getDetailById(id);
return jsonObject.toString();
} catch (IOException e) {
System.out.println("图片上传失败");
jsonObject.put("code",0);
return jsonObject.toString();
}
}
@RequestMapping(value = "imageUpdate",produces="text/html;charset=utf-8")
@ResponseBody
public String imageUpdate(MultipartFile file,HttpSession session,HttpServletRequest request){
User user = (User) session.getAttribute("user");
JSONObject jsonObject = new JSONObject();
File oldFile = new File(request.getServletContext().getRealPath(user.getImg()));
System.out.println(oldFile);
if (oldFile.exists()){
// if (oldFile.delete()){
// System.out.println("删除成功");
// }
}
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
String fileName = user.getUsername()+ "-" + new Date().getTime()+suffix;
String src = request.getServletContext().getRealPath("file/user/avatar/" + fileName);
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),new File(src));
userServiceImpl.updImgById(user.getId(),"file/user/avatar/" + fileName);
user.setImg("file/user/avatar/" + fileName);
session.setAttribute("user",user);
jsonObject.put("src","file/user/avatar/" + fileName);
jsonObject.put("code",1);
} catch (IOException e) {
System.out.println("图片上传失败");
jsonObject.put("code",0);
return jsonObject.toString();
}
return jsonObject.toString();
}
@RequestMapping("update")
public String update(User user,HttpSession session,HttpServletRequest req){
System.out.println(user);
@Controller
@RequestMapping("video")
public class VideoController {
@Resource
private VideoService videoServiceImpl;
@RequestMapping("getAll/{pageNum}/{pageSize}")
@ResponseBody
public PageInfo<Video> getAll(@PathVariable("pageNum")int pageNum,@PathVariable("pageSize")int pageSize){
if (pageNum <= 0){
pageNum = 1;
}
if (pageSize <= 0){
pageSize = 30;
}
PageInfo<Video> pageInfo = new PageInfo<>();
pageInfo.setPageSize(pageSize);
pageInfo.setPageNum(pageNum);
pageInfo.setCount(videoServiceImpl.getCount());
pageInfo.setList(videoServiceImpl.getAll(pageInfo));
return pageInfo;
}
@RequestMapping("getAllBySelect/{type}/{category}/{location}/{year}/{pageNum}/{pageSize}")
@ResponseBody
public PageInfo<Video> getAllBySelect(@PathVariable("type")int type,@PathVariable("category")int category
,@PathVariable("location")String location,@PathVariable("year")String year
,@PathVariable("pageNum")int pageNum,@PathVariable("pageSize")int pageSize){
if (pageNum <= 0){
pageNum = 1;
}
if (pageSize <= 0){
} catch (IOException e) {
System.out.println("图片上传失败");
jsonObject.put("code",0);
return jsonObject.toString();
}
}
@RequestMapping(value = "imageUpdate",produces="text/html;charset=utf-8")
@ResponseBody
public String imageUpdate(MultipartFile file,HttpSession session,HttpServletRequest request){
User user = (User) session.getAttribute("user");
JSONObject jsonObject = new JSONObject();
File oldFile = new File(request.getServletContext().getRealPath(user.getImg()));
System.out.println(oldFile);
if (oldFile.exists()){
// if (oldFile.delete()){
// System.out.println("删除成功");
// }
}
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
String fileName = user.getUsername()+ "-" + new Date().getTime()+suffix;
String src = request.getServletContext().getRealPath("file/user/avatar/" + fileName);
try {
FileUtils.copyInputStreamToFile(file.getInputStream(),new File(src));
userServiceImpl.updImgById(user.getId(),"file/user/avatar/" + fileName);
user.setImg("file/user/avatar/" + fileName);
session.setAttribute("user",user);
jsonObject.put("src","file/user/avatar/" + fileName);
jsonObject.put("code",1);
} catch (IOException e) {
System.out.println("图片上传失败");
jsonObject.put("code",0);
return jsonObject.toString();
}
return jsonObject.toString();
}
@RequestMapping("update")
public String update(User user,HttpSession session,HttpServletRequest req){
System.out.println(user);