【发布时间】: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