Spring-boot without template

I have a Spring-Boot app that seems to be out of the norm. This is Spring-MVC, but I do not want to use speed, thimeleaf or anything else. Ideally, I would just use HTML. Then I use jQuery to make my AJAX calls to my REST services, and then populate the pages with returned JSON. The only way I can basically get this to work is to put my html under /src/resources/templates and then have @Controller for each page. Therefore, I have:

@SpringBootApplication

 public class Application { public static void main(String[] args) throws Throwable { SpringApplication.run( Application.class, args ); } } 

and my controllers

 @Controller public class HomeController { @RequestMapping("/") public String getHome() { return "index" } 

and

 @Controller public class AboutController { @RequestMapping("/about") public String getAbout() { return "about" } 

I looked through Spring manuals and sample projects, but I don't see how to set it up. I use startup projects to get Spring-mvc and security, but otherwise I don’t see what I need to do, so go to:

localhost / home or localhost / about or localhost / customer

Or do I need to have @Controller for each page?

+7
spring-boot spring-mvc
source share
1 answer

If you want to use static resources such as HTML and JavaScript, you can put them in a subfolder of /src/main/resources with the name /public , /static or /resources . For example, a file located in /src/main/resources/public/dummy/index.html will be accessible via http://localhost/dummy/index.html . You do not need a controller for this.

See also the Reference Guide .

+7
source share

All Articles