当前位置: 首页 > news >正文

网站模板中企动力今日头条关键词工具

网站模板中企动力,今日头条关键词工具,北京市建设厅网站首页,网页设计策划书方案1、添加LayUI上传组件需要的js文件jquery.min.js、layui.all.js、layer.js2、导入上传组件jar包commons-fileupload、commons-io3、在spring配置文件中限制上传文件的大小&#xff0c;否则会报错<bean id"multipartResolver" class"org.springframework.web.…

1、添加LayUI上传组件需要的js文件

jquery.min.js、layui.all.js、layer.js

2、导入上传组件jar包

commons-fileupload、commons-io

3、在spring配置文件中限制上传文件的大小,否则会报错

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">    <property name="maxUploadSize" value="1048576" />bean>

4、jsp页面代码

class="layui-upload"> <button type="button" class="layui-btn" id="test1">上传图片button>
class="layui-upload-list"> <img class="layui-upload-img" id="previewImg"> <p id="demoText">p> div></div>

5、js代码

<script type="text/javascript">    //图片上传    layui.use('upload', function(){        var $ = layui.jquery            ,upload = layui.upload;        //普通图片上传        var uploadInst = upload.render({            elem: '#test1'            ,url: '/uploadImages'            ,before: function(obj){                //预读本地文件示例,不支持ie8                obj.preview(function(index, file, result){                                      $('#previewImg').attr('src', result); //图片链接(base64)                });            }            ,done: function(res){                //上传失败                if(res.code > 0){                    return layer.msg('上传失败');                }                //上传成功,返回的路径:res.filePath            }            ,error: function(){                //上传失败                return layer.msg('上传失败,请重试!');            }        });    });script>

6、后台java代码及工具类

/** * 文件上传 * @param file * @param request * @param response * @return * @throws Exception */@RequestMapping(value = "/uploadImages",method=RequestMethod.POST)@ResponseBodypublic WebUploadResult uploadImages(MultipartFile file,HttpServletRequest request, HttpServletResponse response) throws Exception {    String destDir = "/upload/picture";    WebUploadResult webResult = new WebUploadResult();    try {        String path = WebUpload.uploads(file, destDir, request,response);        webResult.setStatus(0);        webResult.setFilePath(path);    } catch (Exception e) {        e.printStackTrace();    }    return webResult;}

WebUpload.java类:

import org.springframework.web.multipart.MultipartFile;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.File;import java.text.SimpleDateFormat;import java.util.Date;public class WebUpload {    private static String suffixStrs = "bmp|jpg|png|tiff|gif|pcx|tga|exif|fpx|svg|psd|cdr|pcd|dxf|ufo|eps|ai|raw|WMF";    public static String uploads(MultipartFile file, String destDir, HttpServletRequest request,                                 HttpServletResponse response) throws Exception {        //获取文件上传的真实路径        String uploadPath = request.getSession().getServletContext().getRealPath("/");        try {            //判断上传文件的后缀            String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1);            if (suffixStrs.indexOf(suffix) == -1) {                throw new Exception("上传文件格式不正确");            }            //保存文件的路径            String filepath = destDir + File.separator + createNewDir();            File destfile = new File(uploadPath + filepath);            if (!destfile.exists()) {                destfile.mkdirs();            }            //文件新名称            String fileNameNew = getFileNameNew() + "." + suffix;            File f = new File(destfile.getAbsoluteFile() + File.separator + fileNameNew);            if (f.exists()) {                return filepath + File.separator + fileNameNew;            }            file.transferTo(f);            f.createNewFile();            return filepath + File.separator + fileNameNew;        } catch (Exception e) {            throw e;        }    }    /**     * 为文件重新命名,命名规则为当前系统时间毫秒数     *     * @return string     */    private static String getFileNameNew() {        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS");        return fmt.format(new Date());    }    /*    *以当前日期为名,创建新文件夹    @return    */    private static String createNewDir() {        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");        return fmt.format(new Date());    }}

WebUploadResult.java类:

/** * 默认的页面请求返回的model对象.用来包裹controller的页面输出 */public class WebUploadResult {    private int status;    private String filePath;    private WebUploadError error;    private String id;    public int getStatus() {        return status;    }    public void setStatus(int status) {        this.status = status;    }    public String getFilePath() {        return filePath;    }    public void setFilePath(String filePath) {        this.filePath = filePath;    }    public WebUploadError getError() {        return error;    }    public void setError(WebUploadError error) {        this.error = error;    }    public String getId() {        return id;    }    public void setId(String id) {        this.id = id;    }}

WebUploadError.java类:

/** * 默认的页面请求返回的model对象.用来包裹controller的页面输出 */public class WebUploadError {   private int code;   private String message;   public int getCode() {      return code;   }   public void setCode(int code) {      this.code = code;   }   public String getMessage() {      return message;   }   public void setMessage(String message) {      this.message = message;   }}

注意:

在普通文件上传中,我们都是用

type="file" name="file">

这样来控制上传的。在LayUI上传组件中,实际上也是用这种方式来实现的。

60ce13b75e1e13658b6f9fbb2905eeba.png

http://www.lbrq.cn/news/2482921.html

相关文章:

  • 做教育app的网站有哪些内容百度推广网站平台
  • 现在建设网站挣钱吗今天有什么新闻
  • IT科技资讯新闻类织梦网站模板自媒体135网站免费下载安装
  • 没固定ip怎么做网站性价比高的seo网站优化
  • 泰国vpsseo排名怎样
  • 做网站注册验证码官方百度app下载
  • 程序开发是什么专业网络推广优化培训
  • 阿里云上怎么做网页网站长沙百度推广公司电话
  • 互联网行业适合女生的职位石家庄seo推广公司
  • 卫生室可以做网站吗一站式海外推广平台
  • 下载的网站模板怎么编辑本地免费发布信息网站
  • 深圳网站建设公司电话百度站长快速收录
  • 学校网站建设开发合肥网络科技有限公司
  • 深圳建设局官方网站网页设计需要学什么
  • python做视频点播网站域名怎么注册
  • seo的主要分析工具seo快排软件
  • 杭州市建设网站培训教育机构
  • 如何查看网站权重百度直接打开
  • 做餐饮酒店网站2024年的新闻
  • 天津建设银行公积金缴费网站免费域名申请个人网站
  • 企业宣传网站建设百度开户代理公司
  • 做国外衣服的网站有哪些长尾关键词是什么意思
  • 武汉网站建设yundaow如何做地推推广技巧
  • 济南网站免费制作最火的推广软件
  • 陕西省私募基金协会淘宝关键词优化怎么弄
  • 贵阳做网站的拉新推广渠道
  • 做网咖的网站推广优化seo
  • asp网站模版安装安装百度到手机桌面
  • 网站建设哪家稳妥正规的教育培训机构有哪些
  • 怎样建网站得花多少钱如何给公司网站做推广
  • openmv特征点检测
  • STL——vector
  • 服务器被网络攻击后该如何进行处理?
  • 商汤InternLM发布最先进的开源多模态推理模型——Intern-S1
  • 【lucene】AttributeSource概述
  • uniapp小程序上传图片并压缩