don't dream your life, live your dreams !
Please read : Java spring – quickstart
In fragment 1, create the following controller :
@Controller @RequestMapping("/fragment1") public class Fragment1Controller { @RequestMapping("/helloworld") public ModelAndView method() { String message = "Hello world from spring controller fragment 1 !"; return new ModelAndView("fragment1/helloworld", "message", message); } } |
In fragment 2, create the following controller :
@Controller @RequestMapping("/fragment2") public class Fragment2Controller { @RequestMapping("/helloworld") public ModelAndView method() { String message = "Hello world from spring controller fragment 2 !"; return new ModelAndView("fragment2/helloworld", "message", message); } } |
If you use maven, add the dependencies in your pom.xml :
<dependency> <groupId>${project.groupId}</groupId> <artifactId>web-fragment-1-jar</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>web-fragment-2-jar</artifactId> <version>${project.version}</version> </dependency> |
Now if you request http://localhost:8080/fragment1/helloworld, you will have the following message :
Hello world from spring controller fragment 1 !
Now if you request http://localhost:8080/fragment2/helloworld, you will have the following message :
Hello world from spring controller fragment 2 !
Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.
admin