怎样实现多条大数据界面在界面上的列表显示,支持分页显示

如何实现解析数据的分页显示_百度知道
如何实现解析数据的分页显示
我有更好的答案
基本上就是数据源里先只放10条, 点击最后一个cell时, 添加更多的数据到数据源中. 比如:数据源是个array:NSMutableArray *ViewController的这个方法返回数据条数: +1是为了显示&加载更多&的那个cell- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int count = [items count];
count + 1;}这个方法定制cell的显示, 尤其是&加载更多&的那个cell:- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if([indexPath row] == ([items count])) {
//创建loadMoreCell
return loadMoreC
//create your data cell}还要处理&加载更多&的那个cell的选择事件,触发一个方法来加载更多数据到列表- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [items count]) {
[loadMoreCell setDisplayText:@&loading more ...&];
[loadMoreCell setAnimating:YES];
[self performSelectorInBackground:@selector(loadMore) withObject:nil];
//[loadMoreCell setHighlighted:NO];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
//其他cell的事件
}加载数据的方法:-(void)loadMore{
NSMutableArray *
//加载你的数据
[self performSelectorOnMainThread:@selector(appendTableWith:) withObject:more waitUntilDone:NO];}添加数据到列表:-(void) appendTableWith:(NSMutableArray *)data{
for (int i=0;i&[data count];i++) {
[items addObject:[data objectAtIndex:i]];
NSMutableArray *insertIndexPaths = [NSMutableArray arrayWithCapacity:10];
for (int ind = 0; ind & [data count]; ind++) {
NSIndexPath
*newPath =
[NSIndexPath indexPathForRow:[items indexOfObject:[data objectAtIndex:ind]] inSection:0];
[insertIndexPaths addObject:newPath];
[self.tableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationFade];}
采纳率:82%
来自团队:
为您推荐:
其他类似问题
分页显示的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。等等等等等等等等等等完等相关问答等完完完等完完完等等完等最近浏览暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级暂无贡献等级扫描二维码关注最代码为好友"/>扫描二维码关注最代码为好友layer学习笔记之table表格引入数据实现分页
时间: 17:09:08
&&&& 阅读:752
&&&& 评论:
&&&& 收藏:0
标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&LayUI是一款免费,开源,轻量级的前端cms框架,适用于企业后端,能快速上手开发,集成了常用的组件,还有完善的文档和社区。
最近一直在学习使用layer的layui框架技术,这个主要表现在于弹出层的使用,但是layer页面效果使用也是非常好用的。
之前写一个一个关于数据的table表格显示 并带有分页功能,实现过程遇到了很多问题,现抽空总结一下。
使用之前请先详细阅读layer的文档:
首先下载最新版的layui文件:
下载完之后引入到自己的项目中,放在根目录的下面某一个地方:
然后在你要用的jsp页面上引入相应的js和css:
此时路径应为你放至layui文件包的路径,注意路径不要引入错误!
简单的一个demo页面:
页面显示为:
在此讲一下传入的数据格式:
{"code":0,"msg":"","count":29,"data":[{"id":10000,"username":"user-0",...........
这个是你后台需要返回的数据格式,可以自己定义:
我自己定义方式为:
首先创建一个返回类型实体类:&ResultUtil :
写相应的get,set方法,然后按照layui定义的返回类型格式写这个方法的实现类:
其中object就是你要在表格中显示的数据,count为数据的条数,然后写相应的方法,sql语句 这些都很简单,在此不多说,写完之后
在控制层方法中也就是前台页面url这个路径的方法中调用此方法,注意方法的接口http请求类型,默认:get:
然后在前台页面中使用:
红圈圈中的这个方法在页面控制台可以看到你传入的数据。你传入的data数据一定要和你页面上写的数据一致。
这个是简单的layui展示table表格的实现过程。
接下来讲一讲分页:
layui有自带的分页功能,样式还是很好看的,开启分页的方法:
开启之后可以自定义分页的样式:
此时分页包括分页的样式都已经弄好,但是问题就是我们页面的数据还是查出来的那么多条,并没有根据layui定义分页去显示,这个怎么去解决?
这个问题就是说的重点:实现table表格数据的分页:
因为静态json不支持表格自带分页,所以我们要在后台定义好分页的数据传入前台页面。表格设置了page:true之后,就证明分页功能启用了,剩下的就是后台controller中获得默认传过去的limit和page两个个参数,根据参数计算获得当前页显示的数据,然后把数据打包为指定的json格式设置返回值就ok了
其实现方法有两种:
第一种:自定义原生的sql语句分页:在前台页面配置的table中开启分页以后访问url路径的时候会传过去两个参数,page和limit。page为当前的页码,limit为你定义的分页条数,这样可以在后台方法中
接收这两个参数:
接收之后我们要对page进行重新定义,方便于sql语句的分页:
这样之后调用service层方法到mapper文件的sql语句可以直接这样写(demo示例):
select 数据,数据,数据,......& &from 表名 limit #{pages,jdbcType=INTEGER},#{limit,jdbcType=INTEGER}
这样之后 页面就实现分页了,很简单的。
接下来说说第二中更为方便的写法:
就是使用框架的配置:
首先引入相应的jar包:
然后在mybatis-config.xml中配置分页:
请注意上图中我用红色圈圈中的两个参数,这个两个很重要,在dao层写接收page和limit两个参数的时候需要用到:
不管接受到的参数为什么 注解中一定要用到配置中设定的参数数据,这样框架才会帮你解析。
配置成功之后 控制层后台只需接受这两个参数,sql语句只需写个简单的查询就可以了,框架会自动帮你实现分页。
至此分页讲完。
接下来额外补充一下页面数据的转换:
比如说页面上展示的是个人信息:性别字段数据表中存储的是int类型0或者1& 但是在页面上需要用男和女展示出来,有两种实现方式;
第一中很简单& 直接在后台service实现方法中给替换成相应的类型,我主要说第二中页面中替换:
首先请先仔细阅读官方开发文档:
请注意这个字段:
点击详见自定义模板:
在table定义中需要转义的字段后面加上templet这个参数(模板选择器):
然后写templet对应的模板,它可以存放在页面的任意位置。模板遵循于&&语法,可读取到返回的所有数据:
注意两者的对应关系:
模板中第一个个我只写了一个“男”,这个只是将数字1转为为男在页面上显示,第一个我加了一个span,这个不仅仅是将0替换成“女”,而且还改变了其颜色。
只要认真阅读了layui开发文档这样都可以实现,接下来我说一个layui文档中没有详细说明百度资料也很少的数据转换例子:
将后台传过来的时间戳转为为时间显示:一般如果table表格中设计时间这个列表:后台传入前台都会传过来一串数字:
我在layui官网文档上没有看见介绍转换时间的,只有在layui的table表头参数一览表中的
中提及了一下使用自定义模板去转换,但是具体怎么转换并没有详细说明,百度网上的例子也非常少,经过长时间查找,终于有所收获:
首先在前台页面上定义一个转换时间的js方法:
然后在需要转换时间的表头列上加上参数:templet去调用这个时间转换的方法:
这样转换完之后为:
这种格式。如果不满足请自己查找资料更换。
这些是在学习layer.layui中遇到的问题总结一下,后续慢慢添加相关问题解决方案。标签:&&&&&&&&&&&&&&&&&&&&&&&&&&&原文地址:https://www.cnblogs.com/ka-bu-qi-nuo/p/8405774.html
&&国之画&&&& &&&&chrome插件&&
版权所有 京ICP备号-2
迷上了代码!怎么实现数据窗口分页显示 - PB当前位置:& &&&怎么实现数据窗口分页显示怎么实现数据窗口分页显示www.MyException.Cn&&网友分享于:&&浏览:238次如何实现数据窗口分页显示数据窗口中的数据有很多,要是用滚动条好像太累了,怎么让它分页显示呢?------解决方案--------------------
DW中的按钮可以直接实现上页,下页,最后页等!
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有查询出结果集然后在查看单个详情页面上要使用上一条 下一条的翻页功能如何实现 - ITeye问答
Java编程:
通过组合条件查询出一组数据,在页面显示出来是经过分页处理的,现在的要求是从列表页面要进入到详情页面,在详情页面有下一条的链接,怎么实现这个下一条、上一条的功能,其中涉及到ID不连续的问题,单纯的ID+1或ID-1都不现实,如果可以用js实现不知道如何处理,目的是查看这个list中的第一条数据详情时候不显示上一条只显示下一条,当点击到list最后一个记录的时候只显示上一条
下面给出两个图来说明下
第一个是查询出的list页面
第二个是详情页面
自定义Tag实现的,代码如下:
&%@ taglib uri="/META-INF/web-tags.tld" prefix="wt" %&
&wt:pager styleClass="pager" form="ulist" pagable="${userForm}" url="/app/user.do?action=doSearch" alwaysShow="true"&
&span class="pager_left"&
第${userForm.pageIndex}页/共${userForm.pageCount}页
本页${userForm.pageIndex ne userForm.pageCount ? userForm.pageSize : userForm.recordCount - (userForm.pageIndex-1) * userForm.pageSize}行/共${userForm.recordCount}行
&span class="pager_right"&
&wt:numeric count="10" indexPosition="center" style="width:20 height:20 border:1px solid #CCCCCC; color: display:inline- margin:1 text-align:" currentIndexStyle="width:20 height:20 border:1px solid #CCCCCC; color:#0066CC; display:inline- margin:1 text-align:"/&
&wt:first type="image" image="/resource/pager/first.jpg" title="第一页"/&
&wt:previous type="image" image="/resource/pager/previous.jpg" title="上一页"/&
&wt:forward type="image" image="/resource/pager/next.jpg" title="下一页"/&
&wt:last type="image" image="/resource/pager/last.jpg" title="最后页"/&
转到第&wt:indexBox/&页
&/span&
&/wt:pager&
标签部署描述文件web-tags.tld
&?xml version="1.0" encoding="UTF-8" ?&
&taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1"&
&description&&/description&
&display-name&Web-tags&/display-name&
&tlib-version&1.1&/tlib-version&
&short-name&web-tags&/short-name&
&uri&http://www.kinginfo.net/jsp/jstl/web&/uri&
&name&pager&/name&
&tag-class&net.kinginfo.base.web.tag.Pager&/tag-class&
&body-content&JSP&/body-content&
&attribute&
&name&styleClass&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&style&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&disabled&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&url&/name&
&required&true&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&pagable&/name&
&required&true&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&form&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&alwaysShow&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&name&first&/name&
&tag-class&net.kinginfo.base.web.tag.FirstPageButton&/tag-class&
&body-content&JSP&/body-content&
&attribute&
&name&styleClass&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&style&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&disabled&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&type&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&title&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&text&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&image&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&name&previous&/name&
&tag-class&net.kinginfo.base.web.tag.PreviousPageButton&/tag-class&
&body-content&JSP&/body-content&
&attribute&
&name&styleClass&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&style&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&disabled&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&type&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&title&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&text&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&image&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&name&forward&/name&
&tag-class&net.kinginfo.base.web.tag.ForwardPageButton&/tag-class&
&body-content&JSP&/body-content&
&attribute&
&name&styleClass&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&style&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&disabled&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&type&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&title&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&text&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&image&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&name&last&/name&
&tag-class&net.kinginfo.base.web.tag.LastPageButton&/tag-class&
&body-content&JSP&/body-content&
&attribute&
&name&styleClass&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&style&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&disabled&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&type&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&title&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&text&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&image&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&name&numeric&/name&
&tag-class&net.kinginfo.base.web.tag.NumericPageButton&/tag-class&
&body-content&JSP&/body-content&
&attribute&
&name&styleClass&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&style&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&currentIndexClass&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&currentIndexStyle&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&disabled&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&type&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&title&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&indexPosition&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&count&/name&
&required&true&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&name&indexBox&/name&
&tag-class&net.kinginfo.base.web.tag.PagingIndexBox&/tag-class&
&body-content&JSP&/body-content&
&attribute&
&name&styleClass&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&style&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&disabled&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&type&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&name&tree&/name&
&tag-class&net.kinginfo.base.web.tag.WebTree&/tag-class&
&body-content&JSP&/body-content&
&attribute&
&name&styleClass&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&style&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&disabled&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&url&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&dataSource&/name&
&required&true&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&root&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&params&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&rootSign&/name&
&required&true&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&cid&/name&
&required&true&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&pid&/name&
&required&true&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&label&/name&
&required&true&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&renderer&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&type&net.kinginfo.base.web.tag.WebRenderer&/type&
&/attribute&
&attribute&
&name&target&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&name&calendar&/name&
&tag-class&net.kinginfo.base.web.tag.Calendar&/tag-class&
&body-content&JSP&/body-content&
&attribute&
&name&styleClass&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&style&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
&attribute&
&name&disabled&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&name&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&value&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&type&java.lang.Object&/type&
&/attribute&
&attribute&
&name&renderer&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&type&net.kinginfo.base.web.tag.WebRenderer&/type&
&/attribute&
&attribute&
&name&readonly&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&pattern&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&attribute&
&name&extProperties&/name&
&required&false&/required&
&rtexprvalue&true&/rtexprvalue&
&/attribute&
&name&menu&/name&
&tag-class&net.kinginfo.base.web.tag.HorizontalMenuTag&/tag-class&
&body-content&JSP&/body-content&
&attribute&
&name&dispatcher&/name&
&required&false&/required&
&rtexprvalue&false&/rtexprvalue&
&/attribute&
package net.kinginfo.base.web.
import java.io.IOE
import javax.servlet.jsp.JspE
import javax.servlet.jsp.JspW
* 抽象的分页按钮标签类,继承该类的标签必须作为{@link Pager}标签的子标签使用。
* @version 1.0
* @author Johnson Lee
public abstract class AbstractPagingButton extends AbstractWebTag {
* 分页按钮标签的&code&type&/code&属性,为按钮类型,默认值为&code&"test"&/code&,即超链接形式的按钮
protected String type = "text";
* 分页按钮标签的&code&title&/code&属性,鼠标悬停在按钮上显示的标题
protected S
* 分页按钮标签的&code&index&/code&属性,为此按钮所导航的页索引
* 分页按钮标签的&code&text&/code&属性,按钮显示的文本
protected S
* 分页按钮标签的&code&image&/code&属性,图片按钮所对应的图片的URL,
* 只有当&code&type&/code&属性为&code&"image"&/code&时,按钮才以指定的图片显示
protected S
protected String outerHTML() throws JspException {
return this.outerHTML(type);
public int doEndTag() throws JspException {
JspWriter out = this.pageContext.getOut();
out.print(outerHTML());
} catch (IOException e) {
e.printStackTrace();
return super.doEndTag();
private String outerHTML(String type) throws JspException {
Pager pager = (Pager) this.getParent();
StringBuffer outerHTML = new StringBuffer();
String innerHTML = this.innerHTML();
if ("text".equalsIgnoreCase(type)) {
if (index != pager.pagable.getPageIndex()) {
outerHTML.
append("&a href=\"javascript:doPost({pageIndex:").append(index).
append("});\"").
append(styleClass == null ? "" : " class=\"" + styleClass + "\"").
append(style == null ? "" : " style=\"" + style + "\"").
append(title == null ? "" : " title=\"" + title + "\"").
append("&").
append(innerHTML != null && !"".equals(innerHTML.trim()) ? innerHTML : text == null ? (title == null ? String.valueOf(index) : title) : text).
append("&/a&");
outerHTML.
append("&span").
append(styleClass == null ? "" : " class=\"" + styleClass + "\"").
append(style == null ? "" : " style=\"" + style + "\"").
append(title == null ? "" : " title=\"" + title + "\"").
append("&").
append(innerHTML != null && !"".equals(innerHTML.trim()) ? innerHTML : text == null ? (title == null ? String.valueOf(index) : title) : text).
append("&/span&");
} else if ("image".equalsIgnoreCase(type)) {
if (index != pager.pagable.getPageIndex()) {
outerHTML.
append("&a href=\"javascript:doPost({pageIndex:").
append(index).append("});\"").
append(styleClass == null ? "" : " class=\"" + styleClass + "\"").
append(style == null ? "" : " style=\"" + style + "\"").
append(title == null ? "" : " title=\"" + title + "\"").
append("&").
append("&img src=\"").
append(context).
append(image).
append("\" align=\"absmiddle\" border=\"0\"/&").
append("&/a&");
outerHTML.
append("&span").
append(styleClass == null ? "" : " class=\"" + styleClass + "\"").
append(style == null ? "" : " style=\"" + style + "\"").
append(title == null ? "" : " title=\"" + title + "\"").
append("&").append("&img src=\"").append(context).
append(image).append("\" align=\"absmiddle\" border=\"0\"/&").
append("&/span&");
} else if ("button".equalsIgnoreCase(type)) {
if (index != pager.pagable.getPageIndex()) {
outerHTML.
append("&input type=\"button\" onclick=\"doPost({pageIndex:").
append(index).append("});\"").
append(styleClass == null ? "" : " class=\"" + styleClass + "\"").
append(style == null ? "" : " style=\"" + style + "\"").
append(title == null ? "" : " title=\"" + title + "\"").
append(text == null ? innerHTML != null && !"".equals(innerHTML.trim()) ? innerHTML : (title == null ? String.valueOf(index) : " value=\"" + title + "\"") : " value=\"" + title + "\"").
append("/&");
outerHTML.
append("&input type=\"button\"").
append(styleClass == null ? "" : " class=\"" + styleClass + "\"").
append(style == null ? "" : " style=\"" + style + "\"").
append(title == null ? "" : " title=\"" + title + "\"").
append(text == null ? innerHTML != null && !"".equals(innerHTML.trim()) ? innerHTML : (title == null ? String.valueOf(index) : " value=\"" + title + "\"") : " value=\"" + title + "\"").
append("/&");
return outerHTML.toString();
public void setTitle(String title) {
this.title =
public void setType(String type) {
this.type =
public void setText(String text) {
this.text =
public void setImage(String image) {
this.image =
package net.kinginfo.base.web.
import java.util.M
import javax.servlet.ServletR
* 可提交的数据的标签,为了解决提交数据乱码和数据量限制, 所有实现该接口的标签在提交数据时,都采用Form提交方式, Form由标签本身生成
* @version 1.0
* @author Johnson Lee
public interface Postable {
* 返回该标签生成的Form的HTML
* @return {@link StringBuffer}
public String formHTML();
* 获取保存在HttpSession中的参数
* @param request
ServletRequest
* @return Map 参数列表映射
public Map getPagingParams(ServletRequest request);
* 生成提交表单的JavaScript脚本
* @return 返回JavaScript脚本
public String postScript();
package net.kinginfo.base.web.
import java.util.M
import javax.servlet.ServletR
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpS
import net.kinginfo.base.web.GlobalV
* 抽象可提交数据标签
* @version 1.0
* @author Johnson Lee
public abstract class AbstractPostableTag extends AbstractWebTag implements Postable {
protected S
protected String innerHTML() {
return this.bodyContent.getString();
public String formHTML() {
return "";
public Map getPagingParams(ServletRequest request) {
HttpSession session = ((HttpServletRequest) request).getSession();
return (Map) session.getAttribute(GlobalVar.PAGING_PARAMS);
public String postScript() {
StringBuffer script = new StringBuffer();
script.append("&script type=\"text/JavaScript\"&\n").
append("&!--\n").
append("function doPost(params) {").
append("var f=document.forms['").append(id).append("'];").
append("for (var param in params) {").
append("if (f[param]) f[param].value = params[param];").
append("}").
append("f.submit();").
append("}\n").
append("//--&\n").
append("&/script&");
return script.toString();
* 设置表单提交的URL
* @param url URL路径
public void setUrl(String url) {
this.url =
package net.kinginfo.base.web.
import javax.servlet.http.HttpServletR
import javax.servlet.jsp.JspE
import javax.servlet.jsp.PageC
import javax.servlet.jsp.tagext.BodyTagS
* 抽象的Web标签类
* @version 1.0
* @author Johnson Lee
public abstract class AbstractWebTag extends BodyTagSupport {
private static int tagNumber = 0;
* Servlet上下文,即web工程名
protected S
* class样式选择器名称
protected String styleC
protected S
* 是否禁用
protected S
* 扩展属性
protected String extP
* click事件处理器
protected S
* 鼠标悬停事件处理器
protected S
* 鼠标移出事件处理器
protected S
* 鼠标按下事件处理器
protected S
* 键盘按下事件处理器
protected S
* 键盘被按事件处理器
protected S
* 键盘弹起事件处理器
protected S
public int doStartTag() throws JspException {
this.id = String.valueOf("$" + this.hashCode() + "_" + (++tagNumber));
return super.doStartTag();
* 获取呈现该标签(包括所有子标签)的HTML代码
* @return 返回表现该标签的HTML代码
protected abstract String outerHTML() throws JspE
* 获取表现该标签所有子标签(不包括自身)的HTML代码
* @return 返回表现该标签的HTML代码
protected String innerHTML() throws JspException {
return bodyContent == null ? "" : bodyContent.getString();
public void setPageContext(PageContext pageContext) {
super.setPageContext(pageContext);
this.context = ((HttpServletRequest)pageContext.getRequest()).getContextPath();
if (this.context == null) {
this.context = "";
public void setContext(String context) {
this.context =
public void setStyleClass(String styleClass) {
this.styleClass = styleC
public void setStyle(String style) {
this.style =
public void setDisabled(String disabled) {
this.disabled =
public void setOnclick(String onclick) {
this.onclick =
public void setOnmouseover(String onmouseover) {
this.onmouseover =
public void setOnmouseout(String onmouseout) {
this.onmouseout =
public void setOnmousedown(String onmousedown) {
this.onmousedown =
public void setOnkeydown(String onkeydown) {
this.onkeydown =
public void setOnkeypress(String onkeypress) {
this.onkeypress =
public void setOnkeyup(String onkeyup) {
this.onkeyup =
public final String getId() {
return this.
public final void setId(String id) {
public PageContext getPageContext() {
return this.pageC
public void setExtProperties(String extProperties) {
this.extProperties = extP
package net.kinginfo.base.web.
import java.io.IOE
import java.util.I
import java.util.M
import javax.servlet.jsp.JspE
import javax.servlet.jsp.JspW
import net.kinginfo.base.utils.P
import net.kinginfo.base.utils.StringF
* 分页标签
* @author Johnson Lee
public class Pager extends AbstractPostableTag {
private static final long serialVersionUID = 1L;
protected static final String PAGE_INDEX = "\\{pageIndex\\}";
protected static final String PAGE_COUNT = "\\{pageCount\\}";
protected static final String PAGE_SIZE = "\\{pageSize\\}";
protected static final String RECORD_COUNT = "\\{recordCount}";
protected P
protected S
protected boolean alwaysS
public int doEndTag() throws JspException {
JspWriter out = pageContext.getOut();
if (alwaysShow || pagable.getPageCount() & 1) {
out.println(formHTML());
out.println(postScript());
out.println(outerHTML());
} catch (IOException e) {
e.printStackTrace();
return super.doEndTag();
public String postScript() {
StringBuffer script = new StringBuffer();
script.append("&script type=\"text/JavaScript\"&\n").
append("&!--\n").
append("function doPost(params) {").
append("var f=document.forms['").append(id).append("'];").
append("for (var param in params) {").
append("if (f[param]) f[param].value = params[param];").
append("}").
append("try {").
append("var target=document.forms['" + form + "'];").
append("for (var i = 0; i & target.elements. i++) {").
append("var el = target.elements[i];").
append("if (el.name && el.value) {").
append("var newEl = document.createElement('INPUT');").
append("newEl.type='hidden'; newEl.name=el. newEl.value=el.").
append("f.appendChild(newEl);").
append("}}").
append("} catch (e) {}").
append("f.submit();").
append("}\n").
append("//--&\n").
append("&/script&");
return script.toString();
protected String outerHTML() {
StringBuffer outerHTML = new StringBuffer();
outerHTML.append("&div").
append(styleClass == null ? "" : " class=\"" + styleClass + "\"").
append(style == null ? "" : " style=\"" + style + "\"").
append("&").
append(this.bodyContent.getString()).
append("&/div&");
return outerHTML.toString();
public String formHTML() {
StringBuffer formHTML = new StringBuffer();
formHTML.append("&form style=\"margin:0padding:0overflow:\"").
append(id == null ? "" : " name=\"" + id + "\"").
append(" action=\"").append(context).append(url).append("\"").append(" method=\"post\"&").
append("&input type=\"hidden\" name=\"pageIndex\" value=\"").append(pagable.getPageIndex()).append("\"/&").
append("&input type=\"hidden\" name=\"pageSize\" value=\"").append(pagable.getPageSize()).append("\"/&");
Map paramsMaping = this.getPagingParams(pageContext.getRequest());
if (paramsMaping != null) {
for (Iterator it = paramsMaping.keySet().iterator(); it.hasNext();) {
String name = (String) it.next();
String value = String.valueOf(paramsMaping.get(name));
if ("pageIndex".equals(name) || "pageSize".equals(name) || StringFormat.empty(value))
formHTML.append("&input type=\"hidden\" name=\"").append(name).append("\" value=\"").append(paramsMaping.get(name)).append("\"/&");
formHTML.append("&/form&");
return formHTML.toString();
public void setPagable(Pagable pagable) {
this.pagable =
public Pagable getPagable() {
public void setAlwaysShow(boolean alwaysShow) {
this.alwaysShow = alwaysS
public String getForm() {
public void setForm(String form) {
this.form =
package net.kinginfo.base.web.
public class NumericPageButton extends AbstractPagingButton {
private static final long serialVersionUID = 1L;
private String indexP
private String currentIndexS
private String currentIndexC
protected String outerHTML() {
Pager parent = (Pager) this.getParent();
StringBuffer outerHTML = new StringBuffer();
long pageIndex = parent.pagable.getPageIndex();
long pageCount = parent.pagable.getPageCount();
long end = 0;
count = Math.min(count, (int) pageCount);
if ("center".equalsIgnoreCase(indexPosition)) {
end = pageIndex & count / 2 ? count : //中间偏左
pageCount & pageIndex + count / 2 ? pageCount : //中间偏右
pageIndex + count / 2 & count ? count : pageIndex + count / 2;
} else if ("fixed".equalsIgnoreCase(indexPosition)) {
end = pageIndex &= count ? count :
pageCount - pageIndex & count ? pageCount :
(pageIndex - 1) / count * count +
long start = end -
for (long i = start + 1; i &= i++) {
if (i == parent.pagable.getPageIndex()) {
outerHTML.append("&span").
append(currentIndexClass == null ?
styleClass == null ? "" : " class=\"" + styleClass + "\"" :
" class=\"" + currentIndexClass + "\""
append(currentIndexStyle == null ?
style == null ? "" : " style=\"" + style + "\"" :
" style=\"" + currentIndexStyle + "\""
append(title == null ? "" : " title=\"" + title + "\"").
append("&").
append(i).
append("&/span&");
outerHTML.append("&a").
append(styleClass == null ? "" : " class=\"" + styleClass + "\"").
append(style == null ? "" : " style=\"" + style + "\"").
append(title == null ? "" : " title=\"" + title + "\"").
append(" href=\"javascript:doPost({pageIndex:").append(i).append("});\"").
append("&").
append(i).
append("&/a&");
return outerHTML.toString();
public void setCount(int count) {
this.count =
public void setCurrentIndexStyle(String currentIndexStyle) {
this.currentIndexStyle = currentIndexS
public void setCurrentIndexClass(String currentIndexClass) {
this.currentIndexClass = currentIndexC
public void setIndexPosition(String indexPosition) {
this.indexPosition = indexP
package net.kinginfo.base.web.
import javax.servlet.jsp.JspE
import net.kinginfo.base.web.servlet.ResourceM
* 分页标签pager的子标签first——第一页按钮
* @version 1.0
* @author Johnson Lee
public class FirstPageButton extends AbstractPagingButton {
private static final long serialVersionUID = 1L;
public int doStartTag() throws JspException {
this.index = 1;
this.image = ResourceManager.lookup("/pager/first");
return super.doStartTag();
package net.kinginfo.base.web.
import javax.servlet.jsp.JspE
public class PreviousPageButton extends AbstractPagingButton {
private static final long serialVersionUID = 1L;
public int doStartTag() throws JspException {
Pager parent = (Pager) this.getParent();
this.index = parent.pagable.getPageIndex() - 1 & 1 ? 1 : parent.pagable.getPageIndex() - 1;
return super.doStartTag();
package net.kinginfo.base.web.
import javax.servlet.jsp.JspE
* 分页标签pager的子标签forward——下一页按钮
* @author Johnson Lee
public class ForwardPageButton extends AbstractPagingButton {
private static final long serialVersionUID = 1L;
public int doStartTag() throws JspException {
Pager parent = (Pager) this.getParent();
this.index = parent.pagable.getPageIndex() + 1 & parent.pagable.getPageCount() ?
parent.pagable.getPageCount() :
parent.pagable.getPageIndex() + 1;
return super.doStartTag();
package net.kinginfo.base.web.
import javax.servlet.jsp.JspE
public class LastPageButton extends AbstractPagingButton {
private static final long serialVersionUID = 1L;
public int doStartTag() throws JspException {
Pager parent = (Pager) this.getParent();
this.index = parent.pagable.getPageCount();
return super.doStartTag();
package net.kinginfo.base.web.
import java.io.IOE
import javax.servlet.jsp.JspE
import javax.servlet.jsp.JspW
public class PagingIndexBox extends AbstractWebTag {
private static final long serialVersionUID = 1L;
private String type = "select";
public int doEndTag() throws JspException {
JspWriter out = pageContext.getOut();
out.print(this.outerHTML());
} catch (IOException e) {
e.printStackTrace();
return super.doEndTag();
protected String outerHTML() {
Pager parent = (Pager) this.getParent();
StringBuffer outerHTML = new StringBuffer();
if ("select".equalsIgnoreCase(type)) {
outerHTML.append("&select").
append(styleClass == null ? "" : " class=\"" + styleClass + "\"").
append(style == null ? "" : " style=\"" + style + "\"").
append(" onchange=\"var $= doPost({pageIndex:$.value});\"&");
for (int i = 0; i & parent.pagable.getPageCount(); i++) {
outerHTML.append("&option value=\"").append(i + 1).append("\"").
append(parent.pagable.getPageIndex() == i + 1 ? "selected" : "").append("&").
append(i + 1).append("&/option&");
outerHTML.append("&/select&");
return outerHTML.toString();
public void setType(String type) {
this.type =
package net.kinginfo.system.web.
import java.util.L
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import org.apache.struts.action.ActionF
import org.apache.struts.action.ActionF
import org.apache.struts.action.ActionM
import net.kinginfo.base.ConfigM
import net.kinginfo.base.SystemS
import net.kinginfo.base.utils.StringF
import net.kinginfo.base.utils.encrypt.MD5;
import net.kinginfo.base.web.action.BaseA
import net.kinginfo.base.web.action.PagableA
import net.kinginfo.system.AccountLockedE
import net.kinginfo.system.AccountUnLockedE
import net.kinginfo.system.PwdE
import net.kinginfo.system.model.B
import net.kinginfo.system.model.L
import net.kinginfo.system.model.R
import net.kinginfo.system.model.U
import net.kinginfo.system.model.UserR
import net.kinginfo.system.service.BranchS
import net.kinginfo.system.service.RightsS
import net.kinginfo.system.service.RoleS
import net.kinginfo.system.service.UserS
import net.kinginfo.system.web.form.UserF
public class UserAction extends BaseAction implements PagableAction {
private UserService userS
private RoleService roleS
private RightsService rightsS
private BranchService branchS
public BranchService getBranchService() {
return branchS
public void setBranchService(BranchService branchService) {
this.branchService = branchS
public void setUserService(UserService userService) {
this.userService = userS
public void setRoleService(RoleService roleService) {
this.roleService = roleS
public void setRightsService(RightsService rightsService) {
this.rightsService = rightsS
* 转到用户列表视图(查询)
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward doSearch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UserForm userForm = (UserForm)
List userList = this.userService.getPage(userForm.getUser(), userForm);
userForm.setUserList(userList);
return mapping.findForward("userListView");
* 转到查看用户视图
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward toUserDetailsView(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UserForm userForm = (UserForm)
User user = (User) this.userService.get(User.class, userForm.getUser().getId());
userForm.setUser(user);
return mapping.findForward("userDetailsView");
* 转到新增用户视图
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward toUserAddView(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UserForm userForm = (UserForm)
List roleList = this.roleService.findAll(Role.class);
//List branchList = this.userService.findAll(Branch.class);
//userForm.setBranchList(branchList);
List branchList = this.branchService.getUsableParents(SystemSession.getCurrentUser().getBranch());
userForm.setBranchList(branchList);
userForm.setRoleList(roleList);
return mapping.findForward("userAddView");
* 转到编辑用户视图
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward toUserEditView(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UserForm userForm = (UserForm)
User user = (User) this.userService.get(User.class, userForm.getUser().getId());
List branchList = this.branchService.getUsableParents(SystemSession.getCurrentUser().getBranch());
userForm.setBranchList(branchList);
userForm.setUser(user);
return mapping.findForward("userEditView");
* 转到选择用户视图
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward toUserSelectView(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UserForm userForm = (UserForm)
List userRoleList = this.userService.getPage(userForm.getUserRole(), userForm);
List branchList = this.userService.findAll(Branch.class);
userForm.setUserRoleList(userRoleList);
return mapping.findForward("userSelectView");
* 新增用户
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward doAddUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UserForm userForm = (UserForm)
ActionForward forward = mapping.findForward("toUserListView");
User user = SystemSession.getCurrentUser();
String admin = ConfigManager.config("admin");
UserRole roleId = this.userService.getUserRoleByUserId(user);
UserRole userRole = new UserRole();
userRole.setRole(roleId.getRole());
userRole.setUser(userForm.getUser());
this.userService.save(userRole);
String msg = StringFormat.format("新增用户{0}成功", new Object[]{userForm.getUser().getId()});
this.addMessage(msg);
this.log(request, msg, Log.OPERATION, "用户管理");
* 编辑用户
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward doEditUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UserForm userForm = (UserForm)
ActionForward forward = mapping.findForward("toUserListView");
User user = userForm.getUser();
User user = (User) this.userService.get(User.class, userForm.getUserRole().getUser().getId());
//用户角色
UserRole userRole = (UserRole) this.userService.get(UserRole.class, userForm.getUserRole().getId());
Role role = (Role) this.roleService.get(Role.class, userForm.getUserRole().getRole().getId());
//组织机构
Branch branch = (Branch) this.userService.get(Branch.class, userForm.getUserRole().getUser().getBranch().getId());
String newPassword = userForm.getUserRole().getUser().getPassword();
if (!user.getPassword().equals(newPassword)) {//数据库与界面一致,则不用更新
user.setPassword(MD5.encrypt(newPassword));
userRole.setRole(role);
user.setName(userForm.getUserRole().getUser().getName());
user.setBranch(branch);
user.setUpdater(currentUser.getId());
user.setUpdateTime(new Date());*/
this.userService.update(user);
String msg = StringFormat.format("编辑用户{0}成功", new Object[]{user.getId()});
this.addMessage(msg);
this.log(request, msg, Log.OPERATION, "用户管理");
* 锁定用户
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward doLockUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UserForm userForm = (UserForm)
UserRole userRole = (UserRole) this.userService.get(UserRole.class, userForm.getUserRole().getId());
if (userRole.getUser().getState() == User.LOCK) {
throw new AccountLockedException();
userRole.getUser().setState(User.LOCK);
this.userService.update(userRole.getUser());
String msg = StringFormat.format("锁定用户{0}成功", new Object[]{userRole.getUser().getId()});
this.addMessage(msg);
this.log(request, msg, Log.OPERATION, "用户管理");
return mapping.findForward("toUserListView");
* 解锁定用户
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward doUnLockUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UserForm userForm = (UserForm)
UserRole userRole = (UserRole) this.userService.get(UserRole.class, userForm.getUserRole().getId());
if (userRole.getUser().getState() == User.NORMAL) {
throw new AccountUnLockedException();
userRole.getUser().setState(User.NORMAL);
this.userService.update(userRole.getUser());
String msg = StringFormat.format("解锁用户{0}成功", new Object[]{userRole.getUser().getId()});
this.addMessage(msg);
this.log(request, msg, Log.OPERATION, "用户管理");
return mapping.findForward("toUserListView");
* 删除用户
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward doDeleteUser(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UserForm userForm = (UserForm)
User user = (User) this.userService.get(User.class, userForm.getUser().getId());
this.userService.delete(user);
String msg = StringFormat.format("删除用户{0}成功", new Object[]{user.getId()});
this.addMessage(msg);
this.log(request, msg, Log.OPERATION, "用户管理");
return mapping.findForward("toUserListView");
* 转到编辑密码页面
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward toEditPwd(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
return mapping.findForward("toEditPwd");
* 编辑密码
* @param mapping
* @param form
* @param request
* @param response
* @throws Exception
public ActionForward doEditPwd(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
UserForm userForm = (UserForm)
User user = userForm.getUserRole().getUser();
User currUser = SystemSession.getCurrentUser();
String newPwd = userForm.getNewPwd();
String currPwd = currUser.getPassword();
String oldPwd = MD5.encrypt(user.getPassword());
//判断旧密码是否正确
if(!currPwd.equals(oldPwd)) {
throw new PwdException();
currUser.setPassword(newPwd);
this.userService.update(currUser);
String msg = StringFormat.format("修改成功", new Object[]{currUser.getId()});
this.addMessage(msg);
this.log(request, msg, Log.OPERATION, "用户管理");
return mapping.findForward("toIndexView");
package net.kinginfo.system.web.
import java.util.L
import java.util.M
import net.kinginfo.base.web.form.BaseF
import net.kinginfo.system.model.B
import net.kinginfo.system.model.R
import net.kinginfo.system.model.U
import net.kinginfo.system.model.UserR
public class UserForm extends BaseForm {
private static final long serialVersionUID = 1L;
private UserRole userRole = new UserRole();
private User user = new User();
private List roleL
private List userRoleL
private List branchL
private Map userR
private String newP
private List userL
public List getUserList() {
return userL
public List getBranchList() {
return branchL
public void setBranchList(List branchList) {
this.branchList = branchL
public void setUserList(List userList) {
this.userList = userL
public User getUser() {
if(this.user.getBranch() == null) {this.user.setBranch(new Branch());}
public void setUser(User user) {
this.user =
public UserRole getUserRole() {
if (userRole.getUser() == null) {
userRole.setUser(new User());
if (userRole.getRole() == null) {
userRole.setRole(new Role());
return userR
public String getNewPwd() {
return newP
public void setNewPwd(String newPwd) {
this.newPwd = newP
public void setUserRole(UserRole userRole) {
this.userRole = userR
public List getRoleList() {
return roleL
public void setRoleList(List roleList) {
this.roleList = roleL
public List getUserRoleList() {
return userRoleL
public void setUserRoleList(List userRoleList) {
this.userRoleList = userRoleL
public Map getUserRights() {
return userR
public void setUserRights(Map userRights) {
this.userRights = userR
package net.kinginfo.base.
import java.util.L
import net.kinginfo.base.utils.P
* 分页查询Service接口
* @see net.kinginfo.base.dao.PagableDao
* @version 1.0
* @author Johnson Lee
public interface PagableService {
* 根据指定实体对象分页查询
* @param bean
查询的实体对象
* @param pagable
实现{@link Pagable}接口的类
* @return 查询结果集
* @throws Exception
public List getPage(Object bean, Pagable pagable) throws E
package net.kinginfo.base.
import java.io.S
import java.util.L
import net.kinginfo.base.DataNotFoundE
* 基于MVC模式的中间服务(Service)层基础接口,该接口及其子接口的实现类通过持用DAO层接口的引用,调用DAO层,Web层中的Action通过持用Service层接口的引用,调用Service层,DAO层及Service层接口或其子接口的实现类将通过Spring
* IOC容器注入到相应的Service和Action中
* @version 1.0
* @author Johnson Lee
public interface BaseService extends PagableService {
* 保存指定的实体对象
* @param bean
待保存的实体对象
* @return 返回该实体对象的主键值
* @throws RuntimeException
public Serializable save(Object bean) throws RuntimeE
* 保存或修改指定的实体对象
* @param bean
待保存或修改的实体对象
* @throws Exception
public void saveOrUpdate(Object bean) throws RuntimeE
* 保存多个实体对象,整个保存操作视为一个事务
* @param beans
待保存的实体对象集合
* @return 返回所有实体对象的主键值集合
* @throws RuntimeException
public Serializable[] save(Object[] beans) throws RuntimeE
* 更新指定的实体对象
* @param bean
待更新的实体对象
* @throws RuntimeException
public void update(Object bean) throws RuntimeE
* 更新指定的实体对象集合,整个更新操作视为一个事务
* @param beans
待更新的实体对象集合
* @throws RuntimeException
public void update(Object[] beans) throws RuntimeE
* 根据指定的类型和主键值删除对象
* @param clazz
待删除的实体对象的类型
* @param id 待删除的实体对象的主键值
* @throws RuntimeException
public void delete(Class clazz, Serializable id) throws RuntimeE
* 删除指定的实体对象
* @param bean
待删除的实体对象
* @throws RuntimeException
public void delete(Object bean) throws RuntimeE
* 删除指定的实体对象集合,整个删除操作视为一个事务
* @param beans
待删除的实体对象集合
* @throws RuntimeException
public void delete(Object[] beans) throws RuntimeE
* 根据主键值查询指定类型的实体对象
* @param clazz
实体对象类型
* @param id
* @return 返回具有指定类型和主键值的实体对象,如果不存在则返回null
* @throws RuntimeException
* @throws Exception
public Object get(Class clazz, Serializable id) throws DataNotFoundE
* 查询指定类型实体类的所有结果集
* @param clazz
* @return 指定实体类型的所有结果集
* @throws RuntimeException
public List findAll(Class clazz) throws RuntimeE
package net.kinginfo.base.service.
import java.io.S
import java.util.L
import net.kinginfo.base.DataNotFoundE
import net.kinginfo.base.dao.BaseD
import net.kinginfo.base.service.BaseS
import net.kinginfo.base.utils.P
import net.kinginfo.base.utils.ReflectionU
public class BaseServiceImpl implements BaseService {
private BaseDao baseD
public void setBaseDao(BaseDao baseDao) {
this.baseDao = baseD
public void delete(Object bean) throws RuntimeException {
this.baseDao.delete(bean);
public void delete(Class clazz, Serializable id) throws RuntimeException {
Object bean = this.get(clazz, id);
this.delete(bean);
public Object get(Class clazz, Serializable id) throws DataNotFoundException {
Object bean = this.baseDao.get(clazz, id);
if (bean == null) {
throw new DataNotFoundException(new Object[]{ReflectionUtils.getSimpleClassName(clazz) + "[" + id + "]"});
public Serializable save(Object bean) throws RuntimeException {
return this.baseDao.save(bean);
} catch (Exception e) {
throw new RuntimeException(e);
public void saveOrUpdate(Object bean) throws RuntimeException {
this.baseDao.saveOrUpdate(bean);
public void update(Object bean) throws RuntimeException {
this.baseDao.update(bean);
public List findAll(Class clazz) throws RuntimeException {
return this.baseDao.findAll(clazz);
public void delete(Object[] beans) throws RuntimeException {
if (beans != null) {
for (int i = 0; i & beans. i++) {
this.baseDao.delete(beans[i]);
public Serializable[] save(Object[] beans) throws RuntimeException {
Serializable[] keys =
if (beans != null) {
keys = new Serializable[beans.length];
for (int i = 0; i & beans. i++) {
keys[i] = this.baseDao.save(beans[i]);
return keys == null ? new Serializable[0] :
public void update(Object[] beans) throws RuntimeException {
if (beans != null) {
for (int i = 0; i & beans. i++) {
this.baseDao.update(beans[i]);
public List getPage(Object bean, Pagable pagable) throws RuntimeException {
return this.baseDao.getPage(bean, pagable);
package net.kinginfo.system.
import net.kinginfo.base.service.BaseS
import net.kinginfo.system.model.U
import net.kinginfo.system.model.UserR
public interface UserService extends BaseService {
public void checkLogin(User user) throws RuntimeE
public UserRole getUserRoleByUserId(User user);
package net.kinginfo.system.service.
import java.io.S
import java.util.D
import java.util.L
import net.kinginfo.base.AuthorizationE
import net.kinginfo.base.ConfigM
import net.kinginfo.base.DataAlreadyExistsE
import net.kinginfo.base.DataNotFoundE
import net.kinginfo.base.SessionOutE
import net.kinginfo.base.SystemS
import net.kinginfo.base.service.impl.BaseServiceI
import net.kinginfo.base.utils.P
import net.kinginfo.base.utils.ReflectionU
import net.kinginfo.base.utils.encrypt.MD5;
import net.kinginfo.system.AccountLockedE
import net.kinginfo.system.dao.UserD
import net.kinginfo.system.model.B
import net.kinginfo.system.model.R
import net.kinginfo.system.model.U
import net.kinginfo.system.model.UserR
import net.kinginfo.system.service.UserS
public class UserServiceImpl extends BaseServiceImpl implements UserService {
private UserDao userD
public void setUserDao(UserDao userDao) {
this.userDao = userD
public Serializable save(Object bean) throws RuntimeException {
User currentUser = SystemSession.getCurrentUser();
Serializable serializable =
UserRole userRole = (UserRole)
this.get(User.class, userRole.getUser().getId());
throw new DataAlreadyExistsException(new Object[]{userRole.getUser().getId()});
}catch(DataNotFoundException e) {
User user = (User) userRole.getUser();
user.setPassword(MD5.encrypt(user.getPassword()));
user.setCreater(currentUser.getCreater());
user.setCreateTime(new Date());
serializable = super.save(user);
if (bean instanceof UserRole) {
super.save(userRole);
public Serializable[] save(Object[] beans) throws RuntimeException {
Serializable[] keys =
if (beans != null) {
keys = new Serializable[beans.length];
for (int i = 0; i & beans. i++) {
keys[i] = this.save(beans[i]);
public void update(Object bean) throws RuntimeException {
User newUser = (User)
User oldUser = (User) this.get(User.class, newUser.getId());
String newPassword = newUser.getPassword();
if (!oldUser.getPassword().equals(newPassword)) {//数据库与界面一致,则不用更新
newUser.setPassword(MD5.encrypt(newPassword));
newUser.setCreater(oldUser.getCreater());
newUser.setCreateTime(oldUser.getCreateTime());
newUser.setUpdater(SystemSession.getCurrentUser().getId());
newUser.setUpdateTime(new Date());
ReflectionUtils.copyProperties(oldUser, newUser);
super.update(oldUser);
public void update(Object[] beans) throws RuntimeException {
if (beans != null) {
for (int i = 0; i & beans. i++) {
this.update(beans[i]);
public void delete(Object bean) throws RuntimeException {
User user = (User)
User oldUser = (User) this.get(User.class, user.getId());
UserRole userRole = this.getUserRoleByUserId(oldUser);
super.delete(userRole);
super.delete(oldUser);
public void delete(Object[] beans) throws RuntimeException {
for (int i = 0; i & beans. i++) {
this.delete(beans[i]);
public void checkLogin(User user) throws RuntimeException {
User temp =
temp = (User) this.get(User.class, user.getId());
} catch (DataNotFoundException e) {
throw new AuthorizationException();
if (temp == null) {
throw new AuthorizationException(new Object[]{user.getId()});
if (!temp.getPassword().equals(MD5.encrypt(user.getPassword()))) {
String c = ConfigManager.PWD_ALLOW_ERR_COUNT;
int count = c == null ? 0 : Integer.parseInt(c);
if (temp.getPwdErrCount() &= count) {
temp.setState(User.LOCK);
this.update(temp);
throw new AccountLockedException();
temp.setPwdErrCount(temp.getPwdErrCount() + 1);
super.update(temp);
throw new AuthorizationException(new Object[]{user.getId()});
} else if (temp.getState() == User.LOCK) {
throw new AccountLockedException();
} else if (temp.getState() == User.DELETE) {
throw new AuthorizationException(new Object[]{user.getId()});
temp.setPwdErrCount(0);
user.setName(temp.getName());
user.setState(temp.getState());
super.update(temp);
ReflectionUtils.copyProperties(user, temp);
public List getPage(Object bean, Pagable pagable) throws RuntimeException {
return this.userDao.getPage(bean, pagable);
public UserRole getUserRoleByUserId(User user) {
return this.userDao.getUserRoleByUserId(user);
package net.kinginfo.base.
import java.util.L
import net.kinginfo.base.utils.P
import net.kinginfo.base.web.form.BaseF
* 分页查询接口,任何实现该接口的DAO类可以通过实现此接口,方便完成分页查询。该接口适用于SSH框架集成的开发,为了尽量减少实体与其它层之间的耦合性,实体Bean不需要实现{@link Pagable}接口,由ActionForm来实现或继承{@link BaseForm},分页查询的实现参考下面代码:
Query query =
Session session = this.getSession();
String hql = "select count(*) " + "from ..."; //统计结果集总行数
query = session.createQuery(hql);
for (int i = 0; i & args. i++) {
query.setParameter(i, args[i]); //设置参数
long recordCount = ((Long)query.uniqueResult()).longValue();
int pageCount = (int) Math.ceil(recordCount * 1.0 / pagable.getPageSize());
pagable.setRecordCount(recordCount);
pagable.setPageCount(pageCount);
//查询当前页的结果集
query = session.createQuery("from ...");
//设置参数
for (int i = 0; i & args. i++) {
query.setParameter(i, args[i]);
query.setFirstResult((pagable.getPageIndex() - 1) * pagable.getPageSize());
query.setMaxResults(pagable.getPageSize());
List list = query.list();
//如果当前页没有查询到数据,则查询前一页,直到查询出数据或到第一页为止
while ((list == null || list.size() &= 0) && pagable.getPageIndex() & 1) {
pagable.setPageIndex(pagable.getPageIndex() - 1);
query.setFirstResult((pagable.getPageIndex() - 1) * pagable.getPageSize());
query.setMaxResults(pagable.getPageSize());
list = query.list();
* @see net.kinginfo.base.utils.Pagable
* @see net.kinginfo.base.service.PagableService
* @version 1.0
* @author Johnson Lee
public interface PagableDao {
* 根据指定实体对象分页查询
* @param bean
查询的实体对象
* @param pagable
实现{@link Pagable}接口的类
* @return 查询结果集
* @throws Exception
public List getPage(Object bean, Pagable pagable) throws RuntimeE
package net.kinginfo.base.
import java.io.S
import java.util.L
import net.kinginfo.base.dao.impl.BaseDaoI
import org.springframework.orm.hibernate3.HibernateC
* 支持Hibernate 3.0的基础数据访问对象(DAO)层接口, 所有实现此接口的DAO持久化子接口可以继承该接口的实现类{@link BaseDaoImpl}以简化代码编写
* @version 1.0
* @author Johnson Lee
public interface BaseDao extends PagableDao {
* 保存指定的实体对象
* @param bean
保存的实体对象
* @return 返回该对象的主键
* @throws Exception
public Serializable save(Object bean) throws RuntimeE
* 保存或修改指定的实体对象
* @param bean
待保存或修改的实体对象
* @throws Exception
public void saveOrUpdate(Object bean) throws RuntimeE
* 更新指定的实体对象
* @param bean
更新的实体对象
* @throws Exception
public void update(Object bean) throws RuntimeE
* 删除指定的实体对象
* @param bean
删除的实体对象
* @throws Exception
public void delete(Object bean) throws RuntimeE
* 根据指定的主键值查询指定类型的实体
* @param clazz
实体对象类型
* @param id
* @return 返回具有指定类型和主键值的实体对象,如果不存在则返回null
* @throws Exception
public Object get(Class clazz, Serializable id) throws RuntimeE
* 根据指定HQL语句及参数查询结果集
* @param hql
* @param args
HQL语句对应的参数列表
* @return 返回该HQL执行产生的结果集
* @throws Exception
public List find(String hql, Object[] args) throws RuntimeE
* 根据指定HQL语句及参数查询唯一结果
* @param hql
* @param args
HQL语句对应的参数列表
* @return 返回结果集中的第一行记录
* @throws Exception
public Object uniqueResult(String hql, Object[] args) throws RuntimeE
* 执行Hibernate存储过程
* @param hibernateCallback
Hibernate存储过程
* @return 返回该Hibernate存储过程的结果
* @throws Exception
public Object execute(HibernateCallback hibernateCallback) throws RuntimeE
* 执行Hibernate存储过程
* @param hibernateCallback
Hibernate存储过程
* @return 返回该Hibernate存储过程的结果集
public List executeFind(HibernateCallback hibernateCallback)
throws RuntimeE
* 查询指定类型实体类的所有结果集
* @param clazz
* @return 指定实体类型的所有结果集
* @throws RuntimeException
public List findAll(Class clazz) throws RuntimeE
package net.kinginfo.base.dao.
import java.io.S
import java.sql.SQLE
import java.util.L
import net.kinginfo.base.dao.BaseD
import net.kinginfo.base.utils.P
import net.kinginfo.base.utils.ReflectionU
import org.hibernate.HibernateE
import org.hibernate.Q
import org.hibernate.S
import org.springframework.orm.hibernate3.HibernateC
import org.springframework.orm.hibernate3.support.HibernateDaoS
* {@link BaseDao}接口实现类
* @version 1.0
* @author Johnson Lee
public class BaseDaoImpl extends HibernateDaoSupport implements BaseDao {
public Object get(Class clazz, Serializable id) throws RuntimeException {
return this.getHibernateTemplate().get(clazz, id);
public Object uniqueResult(final String hql, final Object[] args) throws RuntimeException {
return this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query q = session.createQuery(hql);
for (int i = 0; i & args. i++) {
第一种方式,包括多条件查询都用存储过程来做,建立临时表,有自动增长的id,不多讲诉
第二种方式,如果一个详细记录是一个Bean对象的话,那在增加两个属性,pre,next,这两个都是和你ID一样类型。在分页取数据的时候,分别把上一条和下一条的ID值放到这两个里面,然后到详细页面的时候,如果是根据ID取详细信息的话,不就有了吗。相当于把前后都建立连接关系了。记住:第一条:pre=自己ID,最后一条,next=自己ID
已解决问题
未解决问题

我要回帖

更多关于 大数据界面设计 的文章

 

随机推荐