自定义jar包引用-文件服务器

文件资源服API

  1. 导入自定义工具jar

file_manager_api-1.0-SNAPSHOT.jar

 

 

 

  1. pom中添加依赖

 

 

 

<!--        文件服务器api自定义包引入-->
        <dependency>
            <groupId>com.yt.cnzz</groupId>
            <artifactId>file_manager</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${basedir}/../library/file_manager_api-1.0-SNAPSHOT.jar</systemPath>
        </dependency>

 

 

 

 

3、启动类添加扫描包 com.yt.file_manager

 

4、编写业务代码,调用工具方法

 

package com.mz.party_build.manager_center.test;


import com.alibaba.fastjson.JSONObject;
import com.yt.file_manager.dict.Dict_channel;
import com.yt.file_manager.dto.FileNotRequestData;
import com.yt.file_manager.dto.FileRequestData;
import com.yt.file_manager.dto.FileResponseData;
import com.yt.file_manager.util.RestfulHttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@Controller
@RequestMapping("/TestController")
public class TestController {
    private static Logger log = LoggerFactory.getLogger(TestController.class);

    private String url="http://127.0.0.1:9313/file_manager/fastdfs/upload/image/sample";
    private String channel= Dict_channel.PATY_BUILD;

    @RequestMapping(value = "/test", method = RequestMethod.POST)
    @ResponseBody
    public FileResponseData test(MultipartFile file) {
        log.info("进入了文件测试服");
        FileRequestData fileRequestData=new FileRequestData();
        fileRequestData.setChannel(channel);
        fileRequestData.setFile(file);
        FileResponseData fileResponseData =null;
        try {
            fileResponseData = RestfulHttpUtil.FileManagerPostFile(url, fileRequestData);
        } catch (IOException e) {
            e.printStackTrace();
        }
        log.info("文件测试服结果打印fileResponseData={}", JSONObject.toJSONString(fileResponseData));
       //TODO 解析文件服结果,响应

        return fileResponseData;
    }

    @RequestMapping(value = "/testNoFile", method = RequestMethod.POST)
    @ResponseBody
    public FileResponseData testNoFile(String filePath) {
        log.info("进入了文件测试服 filePath={}",filePath);
        FileNotRequestData fileNotRequestData=new FileNotRequestData();
        fileNotRequestData.setChannel(channel);
        FileResponseData fileResponseData =null;
        try {
            fileResponseData = RestfulHttpUtil.FileManagerPostJson(url, fileNotRequestData);
        } catch (IOException e) {
            e.printStackTrace();
        }
        log.info("文件测试服结果打印fileResponseData={}", JSONObject.toJSONString(fileResponseData));
        //TODO 解析文件服结果,响应
        
        return fileResponseData;
    }
}

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值