Because in the front-end to the data in the dictionary table to convert 1, 2 of these values to the corresponding text interpretation 1. First create a class to implementTemplatedirectivemodel class
@Component Public classDictdirectiveImplementsTemplatedirectivemodel {@Override Public voidExecute (Environment environment, map map, templatemodel[] templatemodels, Templatedirectivebody templatedirectivebody )throwstemplateexception, IOException {defaultobjectwrapperbuilder builder=NewDefaultobjectwrapperbuilder (configuration.version_2_3_25); if(Map.containskey ("type") && map.get ("type")! =NULL) {String type= Map.get ("type"). toString (); List<Dict> dictlist =dictutils.getdictlist (type); if(Map.containskey ("value") && map.get ("value")! =NULL) {String value= Map.get ("Value"). toString (); Dict Dict=NULL; for(Dict dict1:dictlist) {if(Value.equals (Dict1.getvalue (). toString ())) {Dict=Dict1; }} environment.setvariable ("Dict", Builder.build (). Wrap (dict)); }Else{environment.setvariable ("Dictlist", Builder.build (). Wrap (dictlist)); } } if(templatedirectivebody!=NULL) {Templatedirectivebody.render (Environment.getout ()); } }}
2. Create a configuration class
@Component Public class freemarkerconfig { @Autowired private configuration configuration; @Autowired private dictdirective dictdirective; @PostConstruct publicvoidthrows templatemodelexception { Configuration.setsharedvariable ("Dict_tag", dictdirective); }}
Then you can call it on the page.
<type= "News_source" value= "${news.source}"> ${dict.label} </@dict_tag>
The front-end can be arbitrarily passed parameters, such as type, value, all the passed parameters will be stored in the map, the background directly to fetch it.
Springboot Integrated Freemarker Custom tags gets the data from the dictionary table