I am just starting to learn Java, and this is my first question on Stack Overflow, so please do not judge me too harshly )
I use Netbeans 8.02, GlassFish 4.0, JavaEE7, Spring 4.01. (No Maven. No Hibernate.) (New Project->Java Web->Web Application)
I have created "source packages/XController.java" in and for URL localhost:8080/MyProject/x/y.htm I got this working:
@Controller
public class XController {
@RequestMapping("/x/y.htm")
public String yAction(ModelMap modelMap) {
modelMap.put("printme", "Hello World!");
return "x/y";
}
}
Is it possible to get rid of annotations, since they all will have the same rule: if URL is http://localhost:8080/MyProject/a/b it would automatically use AController.BAction() and automatically set view to be WEB-INF/jsp/a/b.jsp ?
ideally the action code would look something like this:
public Void yAction() {
this.modelMap.put("printme", "Hello World!");
}
and if URL would be http://localhost:8080/MyProject/a/b/hello the corresponding method would look like this:
public Void yAction(String msg) {
this.modelMap.put("printme", msg);
}
If Controller or action or view not found, or action has incorrect arguments then just exception, no further resolving needed.
So the question is - what is the correct way to achieve it using modern Spring features, but if it is not possible, then with plain Java?
It is possible to do manually, for example redirect all to same address, then parse URL, and run the corresponding Controller.Method() but that would not look good )