16

I have a Spring-Boot app that is apparently way out of the norm. It's Spring-MVC, but I don't want to use velocity,thymeleaf or anything. Ideally I would just use HTML. Then I use jQuery to make my AJAX calls to my REST services, and then fill in the pages with the returned JSON. The only way I can mostly get this to work is to put my html under /src/resources/templates, and then have a @Controller for each page. So 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 have looked thru the Spring guides and sample projects, but I don't see how to configure this. I am using the starter projects to get spring-mvc and security, but otherwise I don't see what I need to do this so navigating to :

localhost/home or localhost/about or localhost/customer

Or, is it necessary to have a @Controller for each page?

sonoerin
  • 5,015
  • 23
  • 75
  • 132

1 Answers1

15

If you want to use static resources like HTML and JavaScript you can place them into a subfolder of /src/main/resources named /public, /static or /resources. For example a file located at /src/main/resources/public/dummy/index.html will a accessible via http://localhost/dummy/index.html. You won't need a Controller for this.

See also the Reference Guide.

Roland Weisleder
  • 9,668
  • 7
  • 37
  • 59
  • 6
    Thank you @schlauergerd -Is there anyway to not require the html extension on the url? Ideally, typing **localhost/office"** would work, but right now I have to append the ".html" I have **spring.view.prefix=public** and **spring.view.suffix=html** in my application.properties now. – sonoerin Jun 05 '15 at 14:41