第3章 内置组件的应用
作者:ThinkGem
更新日期:2014-01-05
1. 常用组件
1.1. 布局组件
布局文件配置:
/ jeesite/src/main/webapp/WEB-INF/decorators.xml
默认布局文件:
/ jeesite/src/main/webapp/WEB-INF/views/layouts/default.jsp
非公共,自己建立的布局文件:
/ jeesite/src/main/webapp/WEB-INF/views/模块路径/layouts/布局文件.jsp
使用布局文件:
JSP的head里添加:<meta name=”decorator” content=”default”/>
1.2. 用户工具 UserUtils.java fns.tld
应用场景:在java文件或jsp页面上,获取当前用户相关信息
- 获取当前用户:
- getUser();
- currentUser()
- ${fns:getUser()}
- 获取当前用户部门:
- getOfficeList()
- ${fns:getOfficeList()}
- 获取当前用户区域:
- getAreaList()
- ${fns:getAreaList()}
- 获取当前用户菜单:
- getMenuList()
- ${fns:getMenuList()}
- 获取当前用户缓存:
- getCache(key);
- ${fns:getCache(cacheName, defaultValue)}
- 设置当前用户缓存:
- putCache(key);
1.3. 全局缓存 CacheUtils.java
应用场景:系统字典
- 设置应用程序缓存:put(key);
- 获取应用程序缓存:get(key);
1.4. 字典工具 DictUtils.java
应用场景:系统全局固定的字典数据,java或jsp中获取字典相关数据。
- 根据类型和值获取字典标签(列表取值):
- getDictLabel(String value, String type, String defaultValue)
- ${ fns:getDictLabel (value, type, defaultValue)}
- 根据类型和标签获取字典值(根据标签取值):
- getDictValue(String label, String type, String defaultLabel)
- ${fns:getDictValue(label, type, defaultValue)}
- 根据类型获取字典列表(下拉框,复选框,单选框):
- getDictList(String type)
- ${fns:getDictList(type)}
1.5. 功能权限控制
应用场景:访问功能授权,查看权限,编辑权限,导入权限,审核权限。
- 给方法添加权限标志
@RequiresPermissions(“sys:submodule:user:view”)
@RequiresUser
- 菜单中设置权限标志。
- 判断权限:
SecurityUtils.getSubject().isPermitted(“sys:user:edit”);
- 视图中控制按钮(tld):
<shiro:hasPermission name="sys:user:edit"> <input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/> </shiro:hasPermission> <!-- 任何一个符合条件的权限 --> <shiro:hasAnyPermissions name="sys:user:view, sys:user:edit,"> <input id="btnSubmit" class="btn btn-primary" type="submit" value="返 回"/> </shiro: hasAnyPermissions>
1.6. 数据权限
应用场景:某用户访问数据范围:公司及子公司,本公司,部门及子部门,本部门,当前用户,明细设置。
// 生成数据权限过滤条件(dsf为dataScopeFilter的简写,在xml中使用 ${sqlMap.dsf}调用权限SQL)
user.getSqlMap().put(“dsf”, dataScopeFilter(user.getCurrentUser(), “o”, “u”));
<!-- 分页查询用户信息 --> <select id="findList" parameterType="User" resultMap="userResult"> SELECT <include refid="userColumns"/> FROM sys_user a <include refid="userJoins"/> WHERE a.del_flag = '0' <!-- 数据范围过滤 --> ${sqlMap.dsf} </select>
/**
* 数据范围过滤
* @param user 当前用户对象,通过“entity.getCurrentUser()”获取
* @param officeAlias 机构表别名,多个用“,”逗号隔开。
* @param userAlias 用户表别名,多个用“,”逗号隔开,传递空,忽略此参数
* @return 标准连接条件对象
*/
String dataScopeFilter (User user, String officeAlias, String userAlias)
1.7. 智能分页组件
// 设置分页参数,则分页,如果不设置,则根据条件获取全部
user.setPage(page);
// 执行分页查询
page.setList(userDao.findPage(user));
1.8. 树选择组件
标签文件:/ jeesite/src/main/webapp/WEB-INF/tags/treeselect.tag
1.1.1. 区域选择组件
<tags:treeselect id="area" name="area.id" value="${area.id}" labelName="area.name" labelValue="${area.name}" title="区域" url="/sys/area/treeData" cssClass="input-small" allowClear="true" notAllowSelectParent="true"/>
多选需要加 checked=”true” 属性
1.1.2. 公司选择组件
<tags:treeselect id="office" name="office.id" value="${user.office.id}" labelName="office.name" labelValue="${user.office.name}" title="部门" url="/sys/office/treeData?type=1" cssClass="input-small" allowClear="true" notAllowSelectParent="true"/>
多选需要加 checked=”true” 属性
1.1.3. 部门选择组件
<tags:treeselect id="office" name="office.id" value="${user.office.id}" labelName="office.name" labelValue="${user.office.name}" title="部门" url="/sys/office/treeData?type=2" cssClass="input-small" allowClear="true" notAllowSelectParent="true"/>
多选需要加 checked=”true” 属性
1.1.4. 人员选择组件
<tags:treeselect id="user" name="user.id" value="${user.id}" labelName="user.name" labelValue="${user.name}" title="用户" url="/sys/office/treeData?type=3" cssClass="input-small" allowClear="true" notAllowSelectParent="true"/>
多选需要加 checked=”true” 属性
1.9. 文件选择、文件上传组件
<form:hidden path="name" htmlEscape="false" maxlength="255" class="input-xlarge"/> <tags:ckfinder input="name" type="files" uploadPath="/test "/>
1.10. 富文本在线编辑器组件
<form:textarea id="name" htmlEscape="true" path="name" rows="4" maxlength="200" class="input-xxlarge"/> <tags:ckeditor replace="name" uploadPath="/test " />
1.11. 其它工具
/src/main/java/com/thinkgem/jeesite/common/utils/ …
Excel(Export/Import)、StringUtils、DateUtils、FileUtils、Encodes、CookieUtils、Collections3
2. 封装及组件
2.1. 工具类组件
- UserUtils:用户工具类(获取当前用户的相关信息)。
- CacheUtils:系统级别Cache工具类。
- CookieUtils:Cookie操作工具类
- DateUtils:日期时间工具类。
- FileUtils:文件操作工具类。
- StringUtils:字符串操作工具类。
- ExcelExcel导入导出,参考用户导入导出例子。
- Reflections:Java对象操作反射工具类。
- BeanMapper:Bean与Bean,Bean与Conllection的互转
- JaxbMapper:XML与Object互转。
- JsonMapper:JSON与Object互转。
- Cryptos、Digests:密钥工具类SHA1、MD5。
- Collections3:集合对象工具类。
- Encodes:各种编码转换工具类。
- Exceptions:异常工具类。
- FreeMarkers:FreeMarkers模板工具类。
- Identities:唯一标识生成算法工具类(uuid、random)
- PropertiesLoader:属性文件操作工具类
- Threads:线程相关操作工具类。
- tag:HTML在线编辑器。
- tag:在线文件管理。
- tag:Icon图标选择。
- tag:消息弹框。
- tag:验证码。
- tld:系统相关EL函数。
- jQuery:强大的js框架,动态特性,AJAX、插件扩展
- jQuery Validate:基于jQuery的客户端校验插件。
- jBox:基于jQuery的多功能对话框插件。
- zTree:基于jQuery的树结构展示查看。
- My7DatePicker:日期选择控件。
- treeTable:基于jQuery的表格数显示插件。
- CKEditor:富文本在线HTML编辑器。
- CKFinder:在线文件资源管理器。
- SuperSlide:基于jQuery的滑动门插件(滑动图片,Tab,横幅等)。
2.2. 自定义标签组件
2.3. EL 函数组件
2.4. JavaScript 组件
3. 界面UI、CSS、JS
- 主题CSS框架:http://v2.bootcss.com/base-css.html
- 多功能下拉框:http://ivaynberg.github.io/select2/
- 界面文档(查找class,查找css):http://www.bootcss.com/scaffolding.html
- 前端验证: /src/main/webapp/static/jquery-validation/1.11.0/demo/index.html
- 弹出对话框: /src/main/webapp/static/jquery-jbox/2.3/docs/jbox-demo.html
top.$.jBox.open('iframe:'+href,'查看评论',$(top.document).width()-220,$(top.document).height()-180,{ buttons:{"关闭":true}, loaded:function(h){ $(".jbox-content", top.document).css("overflow-y","hidden"); $(".nav,.form-actions,[class=btn]", h.find("iframe").contents()).hide(); $("body", h.find("iframe").contents()).css("margin","10px"); } });