java - Is it possible to have destination view name configurable in spring mvc 3? -
code snippet this:
@controller @requestmapping(value="/test") public class testcontroller { ........ @requestmapping(method=requestmethod.get) public string getcreateform(model model) { model.addattribute(new accountbean()); return "newtest"; } ......... "newtest" hard-coded view name. possible have configured in xml-style spring config file? thank you!
i guess real question how configure properties of autodiscovered bean via xml.
you can defining <bean> same name autodiscovered 1 have (when name of autodiscovered bean not specified, it's assumed classname first letter decapitalized):
@controller @requestmapping(value="/test") public class testcontroller { private string viewname = "newtest"; public void setviewname(string viewname) { this.viewname = viewname; } @requestmapping(method=requestmethod.get) public string getcreateform(model model) { model.addattribute(new accountbean()); return viewname; } } .
<bean id = "testcontroller" class = "testcontroller"> <property name = "viewname" value = "oldtest" /> </bean> another option use @value spel expressions
@value("#{testviewname}") private string viewname; .
<bean id = "testviewname" class = "java.lang.string"> <constructor-arg value = "oldtest" /> </bean> or property placeholders
@value("${testviewname}") private string viewname; .
<context:property-placeholder location = "viewnames" /> viewnames.properties:
testviewname=oldtest
Comments
Post a Comment