1

I am working on Spring Boot application. The general problem is the following: I've created REST API, a few controllers. However, I also have some static HTML files, located in "resources/static".

What I want to achieve, is to configure Spring resolvers so that I could access static content without appending ".html". On practise, I expect to access static HTML by path "ip:port/htmlPage" instead of "ip:port/htmlPage.html"

However, I don't want to create methods like this one:

@Controller
public class ViewMaster {
@RequestMapping("/home")
public String home() {
    return "home";
}

So, properties like

spring.mvc.view.suffix=.html

not working for me. Any possibilities to avoid creation per page endpoint in a controller?

2
  • So how are planning to map the requests to the controllers? Commented Sep 9, 2017 at 16:23
  • @mirmdasif, for example: serve requests after "static" (anything other) by static resources view resolver, otherwise - search for REST endpoints Commented Sep 9, 2017 at 16:28

1 Answer 1

2

After reading your question i have tried a lot but unable to serve html from static folder without extention. What works for me is to create an @RequestMapping like this:

@RequestMapping(value="/static/{htmlName}")
String getStaticHtml(@PathVariable String htmlName){
    return htmlName;
}

And moved html files to templates folder. So there is no need to create different end points to access html pages, just pass the name of html without extention and this will do the trick

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.