r/javahelp • u/INFLATABLE_CUCUMBER • Sep 03 '20
Any simple github projects that combine Spring Webflux for Java's backend, and HTML + JS for frontend?
Hi, I found something a while ago that did this: https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot
https://github.com/ericbv/staticContentWithSpringBoot/tree/master/src/main/resources.
Problem that I couldn't understand with it was that inside of the controller, it said:
@RequestMapping("/offerView")
public String page(){
return "html/offer";
}I couldn't make sense of this path "html/offer", and I'd tried to replicate this relatively simple concept and put it into a WebFlux app, but I couldn't get the thing to work. I'm still searching, but looking for some sort of github project, or example for how to do this linkage, and coming up short. Anyone got any ideas? Thanks
20
Upvotes
2
u/daru567 Sep 03 '20 edited Sep 03 '20
It is basically returning a path which points to the html file and that is what will be returned to whoever calls that API. Usually “html/offer” would be a folder called html under your “main/resources” directory so try putting a simple hello world html file inside like “main/resources/html/offer.html” or maybe “main/resources/static/..” I don’t remember exactly because serving front end display stuff directly from a server call was way in the past if you are planning to build a responsive site. Do you have that file structure in your project? It can also be a custom mapping set in the application-context.xml if i remember correctly that points the real path.
However, since you mentioned html and javascript. You can think of the Spring Webflux as your backend server and html + javascript (frontend) as two separate parts. Your frontend application can be built with popular frameworks such as Angular or ReactJS that uses html and javascript. Your frontend communicates with your backend application with AJAX via RESTful api calls.