文件上传与BeanUtils工具类应用整体Servlet 类代码举例
1.为保存图片URL优化创建常量类
package com.lagou.base;
public final class Constants {
//本地访问地址
public static final String LOCAL_URL = "http://localhost:8080";
}
2. Servlet 类代码展示
package com.lagou.web.servlet;
import com.lagou.base.Constants;
import com.lagou.pojo.Course;
import com.lagou.service.CourseService;
import com.lagou.service.impl.CourseServiceImpl;
import com.lagou.utils.DateUtils;
import com.lagou.utils.UUIDUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.IOUtils;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.ht