Jake Miller Jake Miller - 1 month ago 10
Java Question

Mapping html resources using Spring Boot

I'm using Spring Boot to create a REST API for a site I'm creating. Currently, to access static content, I simply go to the resources name. For example,

/index.html
or
/dashboard.html
. Since I'm using REST controllers, there's no way to map pages to certain URL endings and there's no
web.xml
file since I'm using Spring Boot. (for example, I want
/dashboard
to display the
dashboard.html
file.)

Should I use standard MVC
@Controller
controllers to control my page mapping or is there a better way to do this?

EDIT

I can currently access static content by simply typing in the file name in the URL. (ex.
/index.html
will open the index.)

What I want to know, is how to remap static content. For instance, if I want
/dashboard
to display
dashboard.html
or if I want
/error
to display
/error.html
etc... It'll make it nicer/easier for a user to simply go to
www.mydomain.com/dashboard
instead of having to add the .html endings.

Is there a way to remap pages like this with Spring Boot?

EDIT 2

I wish to have the burden of generating the views of each page placed upon the client's system. In other words, I do NOT want the server to generate each page. I wish to have "templates" essentially which are then turned into useful pages with information VIA a REST API utilized by AngularJS controllers.

Answer

If you want to use Angular, do not implement Thymeleaf (Thymeleaf is not RESTful). Then what you can do is use $routeProvider to specify what static resource to serve to which URI. If you have an index.html in your static dir, Spring Boot will automatically use that as the default page, and then your other static URI's used within Angular will be relative to the index page.

https://docs.angularjs.org/api/ngRoute/provider/$routeProvider

Comments