【问题标题】:Create link to a resource file in the browser在浏览器中创建指向资源文件的链接
【发布时间】:2016-05-28 16:32:52
【问题描述】:

晚上好!

我正在 Spring 中开发一个小型 REST 服务器。面临以下问题:

我需要做一个打开的资源文件夹并发送一个链接到以下形式的文件:

http://localhost:8080/myProjectName/resurses/2.jpg

但我只能使用这种类型的链接:

文件:/D:/apache-tomcat-7.0.69/webapps/ROOT/WEB-INF/classes/2.jpg

我添加的dispatcher-servlet.xml文件:

  <mvc: resources mapping = "/ resources / **" location = "/ resources /" />

在控制器声明的方法中:

@RequestMapping("/get_photo")
public @ResponseBody
RequestUserInfoFull get_photo(@RequestBody String body,
                 HttpServletRequest request, HttpServletResponse response) throws IOException {
    RequestUserInfoFull result = new RequestUserInfoFull();
    UserFullInformation usf = new UserFullInformation();
    Resource anotherResource =context.getResource("2.jpg");
    usf.setPhoto(anotherResource.getURL());
    result.setProfile(usf);
    return result;

请帮助解决这个问题。我将不胜感激。对不起我的英语不好。这很糟糕。而且代码也不是最好的..我刚开始学习Spring :)

【问题讨论】:

    标签: java spring rest model-view-controller


    【解决方案1】:

    我的问题在于 Spring Dispatcher 配置和文件夹结构不正确。

    <mvc:resources mapping="/resources/**" location="/resources/" />
    

    【讨论】:

      猜你喜欢
      • 2011-01-25
      • 2019-01-03
      • 2013-06-10
      • 1970-01-01
      • 2013-12-29
      • 1970-01-01
      • 2018-06-19
      • 1970-01-01
      相关资源
      最近更新 更多