主题 : 实现TemplateDirectiveModel的*码 |
级别: 童生
|
1# 发表于:2016-05-30 17:13:01 IP:111.125.*.*
|
||||
---|---|---|---|---|---|
级别: 童生
|
2# 发表于:2016-05-30 17:13:45 IP:111.125.*.*
public static final String PARAM_INDEXKEY = "indexkey";
@SuppressWarnings({"unchecked", "rawtypes"}) public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { //由map集合中获取参数名为indexkey的值 String indexkey = DirectiveUtils.getString(PARAM_INDEXKEY, params); List<Advert> advert = null; if (indexkey != null) { advert = advertService.findByName(indexkey); } Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params); if (advert!=null){ paramWrap.put(DirectiveUtils.OUT_BEAN, DEFAULT_WRAPPER.wrap(advert)); } Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramWrap); body.render(env.getOut()); DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap); } @Autowired private IAdvertService advertService; } |
||
---|---|---|---|
1
共1页