FastDFS文件上传

1.分页PageHelper
    1.导入jar包:
            <dependency>
                <groupId>com.github.pagehelper</groupId>
                <artifactId>pagehelper</artifactId>
                <version>3.4.2-fix</version>
            </dependency>
    2.在Mybatis配置xml中配置拦截器插件:
        <plugins>
           <plugin interceptor="com.github.pagehelper.PageHelper">
              <property name="dialect" value="mysql"></property>
           </plugin>
        </plugins>
    3.service层代码:
        //在查询前面添加PageHelper
        PageHelper.startPage(page,rows);
        List<TbItem> items=mapper.selectByExample(example);
        //得到分页数据的详细信息对象
        PageInfo<TbItem> info=new PageInfo<>(items);
        //获得总条数
        long total=info.getInfo();
    

2.文件上传
    1.添加jar包:
            <dependency>
                <groupId>commons-fileupload</groupId>
                <artifactId>commons-fileupload</artifactId>
                <version>1.3.1</version>
            </dependency>
    2.配置文件springmvc:
        <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
           <property name="defaultEncoding" value="UTF-8"></property>
           <property name="maxUploadSize" value="5242880"></property>
        </bean>  
    3.controller代码:
        //图片服务器URL地址
        private String IMAGE_SERVER_URL;
        public String picUpload(MultipartFile uploadFile){
            //创建FastDFS客户端
            FastDFSClient fastDfs=new FastDFSClient("classpath:conf/fast.conf");
            //获取文件名
            String  fileName = uploadFile.getOriginalFilename();
            //获取后缀名
            String ext = fileName.substring(fileName.lastIndexOf(".")+1);
            //上传文件返回文件名不包括域名
            String paths = fastDfs.uploadFile(uploadFile.getBytes(), ext);
            //组合图片的全路径
            String path = IMAGE_SERVER_URL+paths;
        // }





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值