Implement/user/edit?id=${id}=${type} substitution in Java;
Introduction Package: Freemark.jar, and
The class code is as follows:
Public classFreemarkertexttemplateutils { Public Staticstring processtexttemplatetostring (String texttemplate, Object model)throwsIOException, templateexception {Configuration cfg=NewConfiguration (); Stringtemplateloader Loader=NewStringtemplateloader (); String name= "Kk_tempate"; Loader.puttemplate (name, texttemplate); Cfg.settemplateloader (loader); Template Template=cfg.gettemplate (name); returnfreemarkertemplateutils.processtemplateintostring (template, model); }}
The unit test code is as follows:
String url= "/user/edit?id=${id}&&type=${type}";
Hashmap<string,object> modelmap=new hashmap<string,object> ();
Modelmap.put ("id", 1);
Modelmap.put ("type", 1);
freemarkertexttemplateutils.processtexttemplatetostring ( URL, modelmap);
Output in:/user/edit?id=1&&type=1