/*
* The MIT License (MIT)
*
* Copyright (c) 2014 [email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.my.xymh.pagehelper;
import org.apache.ibatis.builder.SqlSourceBuilder;
import org.apache.ibatis.builder.StaticSqlSource;
import org.apache.ibatis.builder.annotation.ProviderSqlSource;
import org.apache.ibatis.mapping.*;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.apache.ibatis.reflection.factory.ObjectFactory;
import org.apache.ibatis.reflection.wrapper.DefaultObjectWrapperFactory;
import org.apache.ibatis.reflection.wrapper.ObjectWrapperFactory;
import org.apache.ibatis.scripting.xmltags.DynamicContext;
import org.apache.ibatis.scripting.xmltags.DynamicSqlSource;
import org.apache.ibatis.scripting.xmltags.MixedSqlNode;
import org.apache.ibatis.scripting.xmltags.SqlNode;
import org.apache.ibatis.session.Configuration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Mybatis - sql工具,获取分页和count的MappedStatement,设置分页参数
*
* @author liuzh/abel533/isea533
* @since 3.3.0
* 项目地址 : http://git.oschina.net/free/Mybatis_PageHelper
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class SqlUtil {
private static final List<ResultMapping> EMPTY_RESULTMAPPING = new ArrayList<ResultMapping>(0);
//分页的id后缀
private static final String SUFFIX_PAGE = "_PageHelper";
//count查询的id后缀
private static final String SUFFIX_COUNT = SUFFIX_PAGE + "_Count";
//第一个分页参数
private static final String PAGEPARAMETER_FIRST = "First" + SUFFIX_PAGE;
//第二个分页参数
private static final String PAGEPARAMETER_SECOND = "Second" + SUFFIX_PAGE;
private static final String PROVIDER_OBJECT = "_provider_object";
private static final ObjectFactory DEFAULT_OBJECT_FACTORY = new DefaultObjectFactory();
private static final ObjectWrapperFactory DEFAULT_OBJECT_WRAPPER_FACTORY = new DefaultObjectWrapperFactory();
/**
* 反射对象,增加对低版本Mybatis的支持
*
* @param object 反射对象
* @return
*/
private static MetaObject forObject(Object object) {
return MetaObject.forObject(object, DEFAULT_OBJECT_FACTORY, DEFAULT_OBJECT_WRAPPER_FACTORY);
}
private Parser sqlParser;
//数据库方言 - 使用枚举限制数据库类型
public enum Dialect {
mysql, mariadb, sqlite, oracle, hsqldb, postgresql
}
/**
* 构造方法
*
* @param strDialect
*/
public SqlUtil(String strDialect) {
if (strDialect == null || "".equals(strDialect)) {
throw new IllegalArgumentException("Mybatis分页插件无法获取dialect参数!");
}
try {
Dialect dialect = Dialect.valueOf(strDialect);
String sqlParserClass = this.getClass().getPackage().getName() + ".SqlParser";
try {
//使用SqlParser必须引入jsqlparser-x.x.x.jar
Class.forName("net.sf.jsqlparser.statement.select.Select");
sqlParser = (Parser) Class.forName(sqlParserClass).getConstructor(Dialect.class).newInstance(dialect);
} catch (Exception e) {
//找不到时,不用处理
}
if (sqlParser == null) {
sqlParser = SimpleParser.newParser(dialect);
}
} catch (IllegalArgumentException e) {
String dialects = null;
for (Dialect d : Dialect.values()) {
if (dialects == null) {
dialects = d.toString();
} else {
dialects += "," + d;
}
}
throw new IllegalArgumentException("Mybatis分页插件dialect参数值错误,可选值为[" + dialects + "]");
}
}
/**
* 设置分页参数
*
* @param parameterObject
* @param page
* @return
*/
public Map setPageParameter(MappedStatement ms, Object parameterObject, Page page) {
BoundSql boundSql = ms.getBoundSql(parameterObject);
return sqlParser.setPageParameter(ms, parameterObject, boundSql, page);
}
/**
* 处理count查询的MappedStatement
*
* @param ms
* @param sqlSource
* @param args
*/
public void processCountMappedStatement(MappedStatement ms, SqlSource sqlSource, Object[] args) {
args[0] = getMappedStatement(ms, sqlSource, args[1], SUFFIX_COUNT);
}
/**
* 处理分页查询的MappedStatement
*
* @param ms
* @param sqlSource
* @param page
* @param args
*/
public void processPageMappedStatement(MappedStatement ms, SqlSource sqlSource, Page page, Object[] args) {
args[0] = getMappedStatement(ms, sqlSource, args[1], SUFFIX_PAGE);
//处理入参
args[1] = setPageParameter((MappedStatement) args[0], args[1], page);
}
/**
* 处理SQL
*/
public static interface Parser {
void isSupportedSql(String sql);
String getCountSql(String sql);
String getPageSql(String sql);
Map setPageParameter(MappedStatement ms, Object parameterObject, BoundSql boundSql, Page page);
}
public static abstract class SimpleParser implements Parser {
public static Parser newParser(Dialect dialect) {
Parser parser = null;
switch (dialect) {
case mysql:
case mariadb:
case sqlite:
parser = new MysqlParser();
break;
case oracle:
parser = new OracleParser();
break;
case hsqldb:
parser = new HsqldbParser();
break;
case postgresql:
default:
parser = new PostgreSQLParser();
}
return parser;
}
public void isSupportedSql(String sql) {
if (sql.trim().toUpperCase().endsWith("FOR UPDATE")) {
throw new RuntimeException("分页插件不支持包含for update的sql");
}
}
/**
* 获取总数sql - 如果要支持其他数据库,修改这里就可以
*
* @param sql 原查询sql
* @return 返回count查询sql
*/
public String getCountSql(final String sql) {
isSupportedSql(sql);
StringBuilder stringBuilder = new StringBuilder(sql.length() + 40);
stringBuilder.append("select count(*) from (");
stringBuilder.append(sql);
stringBuilder.append(") tmp_count");
return stringBuilder.toString();
}
/**
* 获取分页sql - 如果要支持其他数据库,修改这里�
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
前端jsp、jquery、bootstrap,后端 spring、mybatis,集成活动管理、公告管理、新闻管理、校园风采、活动发布、校历管理、学科资源管理等功能于一体的系统。 毕业设计是高等教育阶段学生在完成学业前所进行的一项重要学术任务,旨在检验学生通过学习所获得的知识、技能以及对特定领域的深刻理解能力。这项任务通常要求学生运用所学专业知识,通过独立研究和创新,完成一个实际问题的解决方案或者开展一项有价值的项目。 首先,毕业设计的选择通常由学生根据个人兴趣、专业方向以及实际需求来确定。学生需要在导师的指导下明确研究目标、问题陈述,确立研究的范围和深度。毕业设计可以包括文献综述、需求分析、方案设计、实施与测试等多个阶段,以确保整个过程的科学性和系统性。 其次,毕业设计的完成通常需要学生具备一定的独立思考和解决问题的能力。在研究过程中,学生可能需要采用各种研究方法,如实验、调查、案例分析等,以获取必要的数据和信息。通过这些活动,学生能够培养扎实的专业技能,提升解决实际问题的实际能力。 第三,毕业设计的撰写是整个过程的重要组成部分。学生需要将研究过程、方法、结果以及结论等详细记录在毕业论文中,以展示其研究的全貌和成果。同时,撰写毕业设计还有助于提高学生的学术写作水平,培养清晰、逻辑的表达能力。 最后,毕业设计的评价通常由导师和相关专业人士进行。评价标准包括研究的创新性、实用性、方法的科学性以及论文的质量等方面。学生在毕业设计中获得的成绩也将直接影响其最终的学业成绩和学位授予。 总的来说,毕业设计是高等教育中的一项重要环节,通过此过程,学生不仅能够巩固所学知识,还能培养独立思考和解决问题的能力,为将来的职业发展奠定坚实的基础。
资源推荐
资源详情
资源评论
收起资源包目录
spring、mybatis 基于ssm的校园活动管理.zip (761个子文件)
bootstrap.css 118KB
bootstrap.min.css 111KB
pintuer.css 110KB
ueditor.css 43KB
ueditor.min.css 34KB
froala_editor.min.css 30KB
font-awesome.min.css 21KB
video-js.css 21KB
style.css 18KB
image.css 18KB
video.css 15KB
attachment.css 14KB
video-js.min.css 11KB
shCoreDefault.css 7KB
popup.css 5KB
admin.css 4KB
scrawl.css 4KB
datepicker.css 4KB
datepicker.css 3KB
froala_page.min.css 3KB
codemirror.css 3KB
charts.css 3KB
background.css 2KB
emotion.css 2KB
dialogbase.css 2KB
music.css 2KB
xgxt_login.css 1KB
edittable.css 1KB
template.css 1KB
webuploader.css 515B
help.css 389B
WdatePicker.css 182B
iframe.css 41B
fontawesome-webfont.eot 55KB
vjs.eot 3KB
UEditorSnapscreen.exe 508KB
wface.gif 49KB
jxface2.gif 40KB
yface.gif 28KB
bface.gif 27KB
icons.gif 20KB
file-icons.gif 20KB
file-icons.gif 20KB
tface.gif 19KB
fface.gif 18KB
cface.gif 8KB
icons-all.gif 4KB
img.gif 2KB
videologo.gif 2KB
img.gif 2KB
cancelbutton.gif 1KB
button-bg.gif 1KB
lock.gif 1KB
alignicon.gif 1KB
datePicker.gif 1KB
word.gif 1019B
icon_doc.gif 1012B
icon_psd.gif 1009B
icon_rar.gif 1007B
icon_xls.gif 1005B
icon_mv.gif 1001B
icon_ppt.gif 1001B
icon_pdf.gif 996B
icon_mp3.gif 986B
icon_txt.gif 970B
icon_jpg.gif 950B
icon_exe.gif 949B
icon_chm.gif 923B
loading.gif 734B
icons.gif 453B
icons.gif 453B
icons.gif 453B
success.gif 445B
success.gif 445B
success.gif 445B
cursor_v.gif 370B
cursor_h.gif 253B
anchor.gif 184B
highlighted.gif 111B
unhighlighted.gif 111B
bg.gif 84B
pagebreak.gif 54B
spacer.gif 43B
0.gif 43B
.gitignore 635B
wordimage.html 6KB
map.html 6KB
emotion.html 6KB
image.html 5KB
show.html 5KB
charts.html 5KB
link.html 4KB
insertframe.html 4KB
video.html 4KB
searchreplace.html 4KB
gmap.html 4KB
scrawl.html 4KB
background.html 3KB
help.html 3KB
edittable.html 2KB
共 761 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
JJJ69
- 粉丝: 6223
- 资源: 5780
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 驱动代码驱动代码驱动代码驱动代码
- SVID_20240523_141155_1.mp4
- Code for the complete guide to tkinter tutorial
- 关于百货中心供应链管理系统.zip
- SimpleFolderIcon-master 修改Unity的Project下的文件夹图标
- A python Tkinter widget to display tile based maps
- A pure Python library for adding tables to a Tkinter application
- Vector资源文件.zip
- MobaXterm-Installer
- MicroMsg.xlsx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功