• 大小: 15.83MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-04
  • 语言: 数据库
  • 标签: SSM  

资源简介

SSM框架图片上传与显示,mysql数据库。mysql文件在项目下db文件夹中

资源截图

代码片段和文件信息

package com.my.controller;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileUploadException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.my.entity.Book;
import com.my.service.BookService;

@Controller
public class ShowController {

@Autowired
private BookService bookService;

// 展示图书列表
@RequestMapping(“/showBookList“)
public String showAllBook(HttpServletRequest request) {
System.out.println(“查询请求到Controller这里“);
List books = this.bookService.findAll();
System.out.println(“查询结果:“ + books.size());

request.setAttribute(“BOOKS“ books);
return “book-list“;
}

// 删除图书
@RequestMapping(“/deleteBook“)
public String delete(HttpServletRequest request @RequestParam(“bookId“) String bookId) {
System.out.println(“删除请求到Controller这里“);

String BId = request.getParameter(“bookId“);
System.out.println(“Id  “ + BId);
this.bookService.deleteBook(BId);
return this.showAllBook(request);
}

// 上傳圖片并回顯
@RequestMapping(“/upload.do“)
public String upload(RedirectAttributes redirectAttributes @RequestParam(“bookName“) String bookName
@RequestParam(“bookId“) String bookId @RequestParam(“bookAuthor“) String bookAuthor
@RequestParam(“bookPrice“) String bookPrice HttpServletRequest request HttpServletResponse response)
throws IOException FileUploadException {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(
request.getSession().getServletContext());
String image = null;
if (multipartResolver.isMultipart(request)) {
MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
Iterator iter = multiRequest.getFileNames();
String myFileName = null;
String myFiledName = null;
while (iter.hasNext()) {
List file = multiRequest.getFiles(iter.next());
if (file != null) {
for (MultipartFile files : file) {
myFileName = files.getOriginalFilename();
myFiledName = files.getName();
if (myFileName.toString().trim() != ““) {
String path = request.getSession().getServletContext().getRealPath(“photo“);
String fileName = null;
long getminsecond = System.currentTimeMillis();
fileName = getminsecond + “_“ + myFileName;
if (myFiledName.equals(“pictures“)) {

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        842  2018-09-09 17:38  SSM-upload\.classpath

     文件        910  2018-09-09 17:38  SSM-upload\.project

     文件        567  2018-09-09 17:38  SSM-upload\.settings\.jsdtscope

     文件         57  2018-09-09 17:48  SSM-upload\.settings\org.eclipse.core.resources.prefs

     文件        364  2018-09-09 17:38  SSM-upload\.settings\org.eclipse.jdt.core.prefs

     文件        482  2018-09-09 17:38  SSM-upload\.settings\org.eclipse.wst.common.component

     文件        345  2018-09-09 17:38  SSM-upload\.settings\org.eclipse.wst.common.project.facet.core.xml

     文件         49  2018-09-09 17:38  SSM-upload\.settings\org.eclipse.wst.jsdt.ui.superType.container

     文件          6  2018-09-09 17:38  SSM-upload\.settings\org.eclipse.wst.jsdt.ui.superType.name

     文件       2701  2018-06-13 14:52  SSM-upload\build\classes\applicationContext.xml

     文件       5928  2018-09-19 15:23  SSM-upload\build\classes\com\my\controller\ShowController.class

     文件        297  2018-09-19 09:57  SSM-upload\build\classes\com\my\dao\BookDao.class

     文件        631  2018-09-19 15:25  SSM-upload\build\classes\com\my\dao\BookDao.xml

     文件       1577  2018-09-19 15:20  SSM-upload\build\classes\com\my\entity\Book.class

     文件        309  2018-09-19 09:57  SSM-upload\build\classes\com\my\service\BookService.class

     文件       1110  2018-09-19 09:57  SSM-upload\build\classes\com\my\service\imp\BookServiceImp.class

     文件        172  2018-09-19 15:26  SSM-upload\build\classes\db.properties

     文件        433  2018-06-13 08:40  SSM-upload\build\classes\log4j.properties

     文件        284  2018-09-09 17:27  SSM-upload\build\classes\mybatis-config.xml

     文件       2041  2018-09-09 17:26  SSM-upload\build\classes\springmvc-config.xml

     文件       2701  2018-06-13 14:52  SSM-upload\src\applicationContext.xml

     文件       3441  2018-09-19 15:23  SSM-upload\src\com\my\controller\ShowController.java

     文件        224  2018-09-09 17:01  SSM-upload\src\com\my\dao\BookDao.java

     文件        631  2018-09-19 15:25  SSM-upload\src\com\my\dao\BookDao.xml

     文件       1223  2018-09-19 15:20  SSM-upload\src\com\my\entity\Book.java

     文件        228  2018-09-09 17:03  SSM-upload\src\com\my\service\BookService.java

     文件        812  2018-09-09 17:05  SSM-upload\src\com\my\service\imp\BookServiceImp.java

     文件        172  2018-09-19 15:26  SSM-upload\src\db.properties

     文件        433  2018-06-13 08:40  SSM-upload\src\log4j.properties

     文件        284  2018-09-09 17:27  SSM-upload\src\mybatis-config.xml

............此处省略72个文件信息

评论

共有 条评论