jeesite使用心得(二)

按照上一篇的内容,有一些缺陷的地方。
分页对象传什么都可以,但是返回的是list<HashMap<String,Object>>集合的话,分页方法就是无效了。

这里把我写的贴一下:

Controller:

// 带条件分页Integer pageNo = null;Integer pageSize = null;if (request.getParameter("pageNo") != null) {pageNo = Integer.parseInt((String) request.getParameter("pageNo"));} else {page.setPageNo(1);pageNo = 1;}if (request.getParameter("pageSize") != null) {pageSize = Integer.parseInt((String) request.getParameter("pageSize"));} else {pageSize = 30;}page.setPageNo(pageNo);page.setPageSize(pageSize);//根据条件查到的集合List<Map<String, Object>> list = busMddkApplicationService.findPage(page, params);page.setList(list);model.addAttribute("page", page);

获取前台传过来的页码和分页数,这样再set到page对象中,前台就可以显示正常的分页和页码了。

jsp页面:

<form:form id="searchForm" modelAttribute="baseBusMddkApplication" action="${ctx}/contract/busMddkApplication/" method="post" class="breadcrumb form-search"><input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/><input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
</form:form>

jsp页面,没改过,就用他生成的就可以。


再说一下shiro的自定义标签:

<shiro:hasAnyPermissions name="contract:busMddkApplication:edit,contract:busMddkApplication:add"></shiro:hasAnyPermissions>

<shiro:hasAnyPermissions ></shiro:hasAnyPermissions>这个标签的意思是有任一权限就可以

<shiro:hasPermission name="contract:busMddkApplication:edit">
<shiro:hasAnyPermissions ></shiro:hasAnyPermissions>这个标签的意思是有某个权限


Controller:

@RequiresPermissions(value= {"contract:busMddkApplication:active","contract:busMddkApplication:edit","contract:busMddkApplication:add","contract:busMddkApplication:info"})
@RequestMapping(value = "form")protected String form(HttpServletRequest request, BusMddkApplicationVo busMddkApplicationVo2, Model model,HttpServletResponse response, RedirectAttributes redirectAttributes) { }

上面的意思是有任一权限就可以进入这个方法。
这是说一下分页的问题,可以用他的page对象,会进入pageInterceptor的拦截器。感觉他查询总数的方法有点问题。贴一下原来的和我改动的代码。


//得到总记录数

common.persistence.interceptor.SQLHelper包下面,在PaginationInterceptor里边先调用 

page.setCount(SQLHelper.getCount(originalSql, null, mappedStatement, parameterObject, boundSql, log));

贴一下他原来的getCount()方法。

public static int getCount(final String sql, final Connection connection,final MappedStatement mappedStatement, final Object parameterObject,final BoundSql boundSql, Log log) throws SQLException {String dbName = Global.getConfig("jdbc.type");final String countSql;if("oracle".equals(dbName)){countSql = "select count(1) from (" + sql + ") tmp_count";//需要优化的sql}else{countSql = "select count(1) from (" + removeOrders(sql) + ") tmp_count";}Connection conn = connection;PreparedStatement ps = null;ResultSet rs = null;try {if (log.isDebugEnabled()) {log.debug("COUNT SQL: " + StringUtils.replaceEach(countSql, new String[]{"\n","\t"}, new String[]{" "," "}));}if (conn == null){conn = mappedStatement.getConfiguration().getEnvironment().getDataSource().getConnection();}ps = conn.prepareStatement(countSql);BoundSql countBS = new BoundSql(mappedStatement.getConfiguration(), countSql,boundSql.getParameterMappings(), parameterObject);//解决MyBatis 分页foreach 参数失效 startif (Reflections.getFieldValue(boundSql, "metaParameters") != null) {MetaObject mo = (MetaObject) Reflections.getFieldValue(boundSql, "metaParameters");Reflections.setFieldValue(countBS, "metaParameters", mo);}//解决MyBatis 分页foreach 参数失效 end SQLHelper.setParameters(ps, mappedStatement, countBS, parameterObject);rs = ps.executeQuery();int count = 0;if (rs.next()) {count = rs.getInt(1);}return count;} finally {if (rs != null) {rs.close();}if (ps != null) {ps.close();}if (conn != null) {conn.close();}}}/** * 去除hql的orderBy子句。 * @param hql * @return */  @SuppressWarnings("unused")private static String removeOrders(String qlString) {  Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE);  Matcher m = p.matcher(qlString);  StringBuffer sb = new StringBuffer();  while (m.find()) {  m.appendReplacement(sb, "");  }m.appendTail(sb);return sb.toString();  }

 这样生成的sql就是正常的条件查询语句外面包了一层select count(1) from(原sql)。
    但是在实际使用过程中,数据量比较大(百万级别),并且查询条件和参数很多的时候,这样会很慢。不如直接select count(1) from (***) 这样的快。
    所以改写了他的getCount()方法,在需要优化的sql的where后边加上'needOptimization' = 'needOptimization'。

public static int getCount(final String sql, final Connection connection,final MappedStatement mappedStatement, final Object parameterObject,final BoundSql boundSql, Log log) throws SQLException {String dbName = Global.getConfig("jdbc.type");final String countSql;if("oracle".equals(dbName)){countSql = "select count(1) from (" + sql + ") tmp_count";//需要优化的sql}else if(sql.contains("needOptimization")){countSql = "select count(1) from "+ removeContent(sql);}else{countSql = "select count(1) from (" + removeOrders(sql) + ") tmp_count";}Connection conn = connection;PreparedStatement ps = null;ResultSet rs = null;try {if (log.isDebugEnabled()) {log.debug("COUNT SQL: " + StringUtils.replaceEach(countSql, new String[]{"\n","\t"}, new String[]{" "," "}));}if (conn == null){conn = mappedStatement.getConfiguration().getEnvironment().getDataSource().getConnection();}ps = conn.prepareStatement(countSql);BoundSql countBS = new BoundSql(mappedStatement.getConfiguration(), countSql,boundSql.getParameterMappings(), parameterObject);//解决MyBatis 分页foreach 参数失效 startif (Reflections.getFieldValue(boundSql, "metaParameters") != null) {MetaObject mo = (MetaObject) Reflections.getFieldValue(boundSql, "metaParameters");Reflections.setFieldValue(countBS, "metaParameters", mo);}//解决MyBatis 分页foreach 参数失效 end SQLHelper.setParameters(ps, mappedStatement, countBS, parameterObject);rs = ps.executeQuery();int count = 0;if (rs.next()) {count = rs.getInt(1);}return count;} finally {if (rs != null) {rs.close();}if (ps != null) {ps.close();}if (conn != null) {conn.close();}}}/*** 将第一个from前的内容删除* @Description:TODO* @author:gmwang* @time:2017年8月29日 上午10:16:28*/private static String removeContent(String sql) {String sqlAfter = StringUtils.substringAfter(sql,"FROM");return sqlAfter;}

如果原来是select count(1) from (
select a.*,b.* from aa a 
left join bb b on a.id = b.id
)
现在就改成了 select count(1) from aa a left join bb b on a.id = b.id
原来的sql执行24秒,现在大约是6秒。




本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/413065.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

jqgrid删除某一列(隐藏)

$("#jqGrid_table").setGridParam().hideCol("列的名字");//隐藏 $("#jqGrid_table").setGridParam().showCol("列的名字");//显示

一个设计项调另一个设计项(支持多选传值)

//方案管理中起企业按钮中的前端代码function(button, record, e) {debugger; // 中断调试指令&#xff0c;可以手动删除它var me this; // this 为列表视图控制器var viewModel this.getViewModel(); // 获取视图模型var grid this.getView();…

[css] 使用css3做一个魔方旋转的效果

[css] 使用css3做一个魔方旋转的效果 总的来说&#xff0c;用了一些 3D 效果的样式&#xff0c;如 translate3d&#xff0c;rotate3d&#xff0c;perspective&#xff0c;transform-style: preserve-3d; 等&#xff0c;感兴趣的可以去看看它的样式文件个人简介 我是歌谣&…

linux安装elasticsearch5.5

大家好&#xff0c;我是烤鸭: 我是采用官网下载tar包的方式安装的。 安装环境&#xff1a;centos 7.2,jdk1.8 下载地址: https://www.elastic.co/downloads/elasticsearch 1.解压缩&#xff1a; 解压 elasticsearch.5.5.2.tar.gz tar -zxvf elasticsearch-5.2.2.tar.gz2.创…

eclipse创建folder变成package解决方案

1,项目右键—-选择properties 2,选择Java Build Path—-选择Source 3,选择xxxx/src/main/resources下面的Excluded,点击Edit 4,在Exclusion patterns下面选中第一个&#xff0c;点击右边的edit 5,方案一&#xff1a;在Browse按钮左边的输入框修改为 ** 方案二&#xff1a;…

[css] 手写一个使用css3旋转硬币的效果

[css] 手写一个使用css3旋转硬币的效果 两种实现方式&#xff1a;1、animationkeyframes 2、transition&#xff1a; //第一种实现方式 <style type"text/css"> .around{ width:200px; height:200px; background:orange; /*圆形的话看不出效果&#xff0c;所以…

0076-小升初1:生日蛋糕

题目 小升初1&#xff1a;生日蛋糕难度级别&#xff1a;B&#xff1b; 运行时间限制&#xff1a;1000ms&#xff1b; 运行空间限制&#xff1a;256000KB&#xff1b; 代码长度限制&#xff1a;2000000B 试题描述一个中学生&#xff08;在线测评系统的系统管理员&#xff09;过生…

tomcat9-jenkins:insufficient free space available after evicting expired cache entries-consider

解决该问题方法&#xff0c;修改tomcat/conf/context.xml文件&#xff0c;增加资源最大可缓存的大小&#xff1a;<Context><!-- Default set of monitored resources. If one of these changes, the --><!-- web application will be reloaded. …

[css] height和line-height的区别是什么呢?

[css] height和line-height的区别是什么呢&#xff1f; height&#xff1a;元素content area的高度line-height&#xff1a;元素中&#xff0c;多行文字基线的距离个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大…

laydate根据开始时间或者结束时间限制范围

$(window).load(function(){//初始化时间控件var cartimeDate laydate.render({elem: #cartime //用车时间,type: datetime,format: yyyy-MM-dd HH:mm,done:function(value, date){returntimeDate.config.mingetDateArray(date);//重点}});var returntimeDate laydate.render…

Django Form -- 字段的用法扩展

form.py的代码 from django import forms from django.forms import fields from django.forms import widgetsclass DetailForm(forms.Form):inp fields.CharField()required inp fields.CharField(requiredFalse)  #表单可以为空 inp fields.CharField(requiredTrue) …

linux部署jenkins,tomcat9

大家好&#xff0c;我是烤鸭&#xff1a;今天分享的是 linux部署jenkins,tomcat9 安装环境&#xff1a;linux centos7.2tomcat 9.1Jenkins 2.73JDK 1.8maven 3.5git 2.91. 下载jenkins&#xff1a;https://jenkins.io/download/ 我选择的war下载。2. 安装…

[css] 请用css写一个扫码的加载动画图

[css] 请用css写一个扫码的加载动画图 Keyframes donut-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .donut { display: inline-block; border: 4px solid rgba(0, 0, 0, 0.1); border-left-color: #7983ff; border-radius: 50%; width: 3…

java.lang.OutOfMemoryError: PermGen space及其解决方法

Run—-Debug Configurations -Xms2096m -Xmx2096m -XX:MaxNewSize2096m -XX:MaxPermSize2096m

【洛谷P1795 无穷的序列_NOI导刊2010提高(05)】模拟

分析 map搞一下 AC代码 #include <bits/stdc.h> using namespace std; map<int,int> mp; inline int read() {int w0,x0; char ch0;while (!isdigit(ch)) {w|ch-;chgetchar();}while (isdigit(ch)) {x(x<<1)(x<<3)(ch^48);chgetchar();}return w?-x:x…

[css] 举例说明伪类:focus-within的用法

[css] 举例说明伪类:focus-within的用法 类似于事件的冒泡机制&#xff0c;可以从获取焦点的元素一职冒泡到根元素上个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试…

jeesite的junit,数据没有插入?

jeesite框架自带的test方法 在common/test/SpringTransactionalContextTests.class 说一下遇到的问题。 sql执行成功了,但是数据库没有数据。what&#xff1f;&#xff1f;&#xff1f; 第一时间就想到了是事务的问题&#xff0c;事务没有提交。 RunWith(SpringJUnit4Class…

Zimbra开发接口文档API下载地址

开源版本下载地址: https://www.zimbra.com/documentation/ 文档API接口下载地址: https://wiki.zimbra.com/wiki/SOAP_API_Reference_Material_Beginning_with_ZCS_8 其他资料(每条互不关联): 1,构建: https://wiki.zimbra.com/index.php?titleBuilding_Zimbra_Desktop…

[css] border-radius:50%和border-radius:100%有什么区别?

[css] border-radius:50%和border-radius:100%有什么区别&#xff1f; 这个实际上可以仔细区分一下&#xff0c;楼上的两个图具体来说应该是 border-top-left-radius 的50%和100%的区别&#xff0c;假如我们直接设置border-radius: 100%; 或者为50%我们会发现这两个图实际上没…

JAVA实现美团电影价格抓取(附代码)

各位老大好&#xff0c;我是烤鸭&#xff1a; 最近在研究爬虫,看到有意思的是美团的电影票价&#xff0c;普通的抓取是抓不到的。例如网址&#xff1a;http://bj.meituan.com/shop/105355906?mtt1.movie/cinemalist.0.0.j8oaf2un&#xff08;当你打开403或者404的话&#xff0…