2016-01-21 43 views
0

我在Eclipse中使用Spring Starter Project(Spring工具套件),因此我没有使用web.xml文件来创建URL映射。如何隐藏Spring Starter项目中的URL扩展(Eclipse中的STS)?

我有一个控制器,哪能网址的映射与@RestController@RequestMapping让我/test.html文件上/test URL访问?

或者你是否有其他解决方案,如.htaccess文件谁在这种类型的项目工作?

谢谢你的时间。

回答

0

答案很简单:把你的HTML文件中src/main/resources/templates/,然后写一个控制器的方法,看起来像这样:

@Controller 
public class YourController { 
    @RequestMapping("/{template}") 
    public String renderTemplate(@PathVariable String template) { 
     return template; 
    } 
} 

春天开机都会知道src/main/resources/templates找一个叫${template}.html文件,并会对其进行渲染。