您的位置:首页 > 其它

关于jeesite字典表的实现,el自定义方法tld

2017-04-10 11:02 1256 查看
用jeesite搭建项目发现字典表非常好用,速度的转义很快,看了下代码,简单的解释下,发现是是使用了el自定义方法tld
1:在jsp的获取方式${fns:getDictList('yes_no')}

 
<div class="control-group">
<label class="control-label">是否允许登录:</label>
<div class="controls">
<form:select path="loginFlag">
<form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
</form:select>
<span class="help-inline"><font color="red">*</font> “是”代表此账号允许登录,“否”则表示此账号不允许登录</span>
</div>
</div>


2:使用fns:要引入fns,用到el 自定义方法 tld

<%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld" %>
3:其实uri中写了fns.tld文件的位置,这个文件中有该方法的自定义函数

fns.tld文件,

<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
<description>JSTL 1.1 functions library</description>
<display-name>JSTL functions sys</display-name>
<tlib-version>1.1</tlib-version>
<short-name>fns</short-name>
<uri>http://java.sun.com/jsp/jstl/functionss</uri>
<function>
<description>获取字典对象列表</description>
<name>getDictList</name>
<function-class>com.thinkgem.jeesite.modules.sys.utils.DictUtils</function-class>
<function-signature>java.util.List getDictList(java.lang.String)</function-signature>
<example>${fns:getDictList(type)}</example>
</function>
</taglib>

写在<function>中<function-class>写了class类<function-signature>写了类里面对应的方法
4.后台写对应的类及方法:特别注意一定为静态方法
public class DictUtils {
private static DictDao dictDao = SpringContextHolder.getBean(DictDao.class);
public static final String CACHE_DICT_MAP = "dictMap";
public static List<Dict> getDictList(String type){
@SuppressWarnings("unchecked")
Map<String, List<Dict>> dictMap = (Map<String, List<Dict>>)CacheUtils.get(CACHE_DICT_MAP);
if (dictMap==null){
dictMap = Maps.newHashMap();
for (Dict dict : dictDao.findAllList(new Dict())){
List<Dict> dictList = dictMap.get(dict.getType());
if (dictList != null){
dictList.add(dict);
}else{
dictMap.put(dict.getType(), Lists.newArrayList(dict));
}
}
CacheUtils.put(CACHE_DICT_MAP, dictMap);
}
List<Dict> dictList = dictMap.get(type);
if (dictList == null){
dictList = Lists.newArrayList();
}
return dictList;
}
}
也会发现使用了缓存,大大提高转换效率
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: