Transfer from Jplus articles
today's first contact with this template engine, it feels very good, usually using spring MVC development, currently teach students to do a small project, using Struts+guice+mybatis, so want to try this template engine open the actual use of the situation.
because the current project fully adopts the 0 configuration scheme, there is a problem
according to the instructions of the Beetl user manual:
need to add Result-types in the Struts2 configuration file to do the following configuration
?
<package name= "Default" namespace= "/" extends= "Struts-default" > ... .
<result-types>
<result-type name= "Beetl" class= "Org.beetl.ext.struts2.Struts2BeetlActionResult" default= "true"/>
</result-types>
<action name= "HelloWorld" class= "example. HelloWorld "> <result>/hello.html</result>
</action> ... </package>
There is absolutely no problem in the general development process based on the struts profile, but if integration with convention will not fully enjoy the functionality of Beetl, unless the annotations are used to complete the complex configuration.
more convenient is the struts2 is open source, according to the source code of the general analysis of the main problem has two points
1. Add convention default result view type
<constant name= "Struts.convention.default.parent.package" value= "Ssia"/><constant name= " Struts.convention.relative.result.types "value=" Dispatcher,velocity,freemarker,beetl "/><package name=" Ssia "Namespace="/"extends=" Convention-default "> <result-types> <result-type name=" Beetl " class= "Org.beetl.ext.struts2.Struts2BeetlActionResult" default= "true"/> </result-types></ Package>
2. Modify the Convention view File scan extension to use our own BTL file as a convention view
<bean type= "Org.apache.struts2.convention.ConventionsService" name= "Beetlservice" class= " Com.ssia.web.struts.plugin.convention.beetl.ConventionsBeetlService "/><constant name=" Struts.convention.conventionsService "value=" Beetlservice "/>public class Conventionsbeetlservice extends Conventionsserviceimpl {@Injectpublic Conventionsbeetlservice ( @Inject ("Struts.convention.result.path") String resultpath) { super (Resultpath);} public map<string, Resulttypeconfig> getresulttypesbyextension ( Packageconfig packageconfig) { map<string, resulttypeconfig> results = Packageconfig.getallresulttypeconfigs (); map<string, resulttypeconfig> resultsbyextension = super.getresulttypesbyextension (packageConfig); Resultsbyextension.put ("Btl", Results.get ("Beetl")); return resultsbyextension;} }
after the modification and configuration of the Struts2-convention plugin and the Beetl template engine will be able to work together, spring MVC does not appear in this kind of situation
Turn: About Beetl integrated struts2 +convention plugin does not recognize the processing scheme of beetl template