├── .DS_Store ├── README.md ├── gencode-base ├── .DS_Store ├── .classpath ├── .gitignore ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ ├── org.eclipse.m2e.core.prefs │ └── org.eclipse.wst.common.project.facet.core.xml ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── tengjie │ │ │ └── common │ │ │ ├── gencode │ │ │ ├── GenCodeTool.java │ │ │ ├── GenUtils.java │ │ │ ├── tools │ │ │ │ ├── BackstageGenCode.java │ │ │ │ ├── DBTool.java │ │ │ │ └── InterfaceAndBackstageFactory.java │ │ │ └── vo │ │ │ │ ├── Dict.java │ │ │ │ ├── GenConfig.java │ │ │ │ ├── GenTable.java │ │ │ │ ├── TableColumn.java │ │ │ │ └── TableMetadata.java │ │ │ └── utils │ │ │ └── freemarker │ │ │ ├── FreeMarkerTools.java │ │ │ ├── GenTemplate.java │ │ │ └── JaxbMapper.java │ └── resources │ │ └── modules │ │ └── gen │ │ ├── config.xml │ │ ├── curd │ │ ├── controller.xml │ │ ├── service.xml │ │ ├── serviceMany.xml │ │ ├── viewForm.xml │ │ ├── viewFormMany.xml │ │ └── viewList.xml │ │ └── dao │ │ ├── dao.xml │ │ ├── entity.xml │ │ ├── extDao.xml │ │ ├── extMapper.xml │ │ └── mapper.xml │ └── test │ └── java │ └── gencode │ └── gencode │ └── AppTest.java └── tengjie-base ├── .DS_Store ├── .classpath ├── .externalToolBuilders └── org.eclipse.wst.validation.validationbuilder (6).launch ├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs ├── org.eclipse.jdt.ui.prefs ├── org.eclipse.ltk.core.refactoring.prefs ├── org.eclipse.m2e.core.prefs ├── org.eclipse.m2e.wtp.prefs ├── org.eclipse.wst.common.project.facet.core.xml └── org.eclipse.wst.validation.prefs ├── LICENSE.txt ├── doc ├── spring-evel解释 └── 程序隐藏加密权限描述.docx ├── pom.xml └── src ├── .DS_Store └── main ├── java └── com │ └── tengjie │ ├── .DS_Store │ ├── cglib │ └── cust │ │ ├── AbstractClassGenerator.java │ │ └── BeanGenerator.java │ └── common │ ├── .DS_Store │ ├── beanvalidator │ └── BeanValidators.java │ ├── config │ └── Global.java │ ├── mapper │ ├── BeanMapper.java │ ├── ConvertBlobTypeHandler.java │ └── JsonMapper.java │ ├── persistence │ ├── .DS_Store │ ├── AppendAutoPutCB.java │ ├── BaseDao.java │ ├── ConditionBean.java │ ├── CrudDao.java │ ├── CustMySqlSchemaStatVisitor.java │ ├── DataEntityFieldCallBackBean.java │ ├── DynaPropertyBeanForRpc.java │ ├── JoinOnBean.java │ ├── JoinTableBean.java │ ├── ModifySelect.java │ ├── Page.java │ ├── PageMap.java │ ├── Parameter.java │ ├── TjBaseEntity.java │ ├── WhereValueBean.java │ ├── annotation │ │ └── MyBatisDao.java │ ├── dialect │ │ ├── Dialect.java │ │ └── db │ │ │ ├── DB2Dialect.java │ │ │ ├── DerbyDialect.java │ │ │ ├── H2Dialect.java │ │ │ ├── HSQLDialect.java │ │ │ ├── MySQLDialect.java │ │ │ ├── OracleDialect.java │ │ │ ├── PostgreSQLDialect.java │ │ │ ├── SQLServer2005Dialect.java │ │ │ ├── SQLServerDialect.java │ │ │ └── SybaseDialect.java │ ├── interceptor │ │ ├── BaseInterceptor.java │ │ ├── MapperModifyPlugin.java │ │ ├── PaginationInterceptor.java │ │ ├── PreparePaginationInterceptor.java │ │ ├── ResultSetInterceptor.java │ │ └── SQLHelper.java │ ├── proxy │ │ ├── PageConfiguration.java │ │ ├── PaginationMapperMethod.java │ │ ├── PaginationMapperProxy.java │ │ └── PaginationMapperRegistry.java │ └── util │ │ ├── CollectFunctionConstantTool.java │ │ ├── DbTablePrimaryKeyFieldConfig.java │ │ ├── JspElement.java │ │ ├── MybatisSqlGetTool.java │ │ ├── PrintDebugSql.java │ │ ├── QueryParamInfoVO.java │ │ ├── RelationOperationTool.java │ │ └── ReturnTypeChangeUtil.java │ ├── service │ ├── BaseService.java │ ├── CrudService.java │ ├── ServiceException.java │ └── ServiceUtils.java │ └── utils │ ├── Base64Utils.java │ ├── BaseCheckUtils.java │ ├── BigdecimalUtils.java │ ├── CacheUtils.java │ ├── CallBackBean.java │ ├── ClassScaner.java │ ├── Collections3.java │ ├── CookieUtils.java │ ├── CustomArrayList.java │ ├── DateUtils.java │ ├── DynaObject.java │ ├── EhCacheUtils.java │ ├── EmojiUtil.java │ ├── Encodes.java │ ├── Exceptions.java │ ├── FileDescEntity.java │ ├── FileSizeHelper.java │ ├── FileUtils.java │ ├── FreeMarkerException.java │ ├── FreeMarkers.java │ ├── GlobalStaticDictBase.java │ ├── GlobalUtils.java │ ├── HttpUtil.java │ ├── IdGen.java │ ├── IdcardUtils.java │ ├── ImageGeo.java │ ├── JavaMailUtils.java │ ├── JedisUtils.java │ ├── ListUtils.java │ ├── MD5Util.java │ ├── MacUtils.java │ ├── MapUtils.java │ ├── MyBeanUtils.java │ ├── MySerializationUtils.java │ ├── MyStringBuffer.java │ ├── NewInstanceUtil.java │ ├── ObjectUtils.java │ ├── OrderProperties.java │ ├── PackageUtil.java │ ├── ParamsUtils.java │ ├── PropertiesLoader.java │ ├── PropertityUtil.java │ ├── QrCodeUtil.java │ ├── Reflections.java │ ├── SendMailUtil.java │ ├── SpringContextHolder.java │ ├── SqlUtils.java │ ├── StreamUtils.java │ ├── StringUtils.java │ ├── SystemPath.java │ ├── Threads.java │ ├── ThreeDES.java │ ├── TimeUtils.java │ ├── TjLinkedMap.java │ ├── TjList.java │ ├── TjMap.java │ ├── TjNewMap.java │ ├── UploadUtils.java │ ├── UserAgentUtils.java │ ├── WorkDayUtils.java │ ├── XmlUtils.java │ └── ZxingHandler.java └── webapp ├── allatori-annotations.jar ├── allatori.jar ├── apache-ant-zip-2.3.jar ├── catalina.jar ├── cglib-3.1.jar ├── ckfinder-2.3.jar ├── javassist.jar ├── pinyin4j-2.5.0.jar └── tomcat-coyote.jar /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | gencode-base为代码生成工具,tengjie-base为动态bean和动态sql的基础项目。 2 | 3 | 1、 引入我们的tengjie-base的jar包。这里我们用的是druid的1.11.14,是因为该项目用的是这个版本 ,也可以用更老的版本 4 | 5 | 2、 需要在mybatis-config.xml中增加如下几个拦截器: 6 | 7 | 8 | 9 | 10 | 分页拦截器 11 | 12 | 动态sql拦截器 13 | 14 | 结果集拦截器 15 | 16 | 17 | 18 | 19 | 20 | 3、使用我们的代码生成器 ,我们可以生成如下代码: 21 | 1:entity 2 mainMapper 4 service 5:dao 6:extdao 7:mapper 22 | 调用方式如下,在您的项目中建立junit两个类 23 | 24 | 第一个类: 25 | 26 | @RunWith(SpringRunner.class) 27 | @SpringBootTest(classes = RuoYiApplication.class) 28 | //由于是Web项目,Junit需要模拟ServletContext,因此我们需要给我们的测试类加上@WebAppConfiguration。 29 | 30 | @WebAppConfiguration 31 | 32 | public class BaseTests { 33 | 34 | @Before 35 | 36 | public void init() { 37 | System.out.println("开始测试-----------------"); 38 | } 39 | 40 | @After 41 | public void after() { 42 | System.out.println("测试结束-----------------"); 43 | } 44 | 45 | } 46 | 47 | 第二个类: 48 | 49 | public class FastGenCode extends BaseTests { 50 | 51 | @Autowired 52 | ApplicationContext applicationContext; 53 | @Test 54 | public void testParse() { 55 | 56 | SpringContextHolder.applicationContext=applicationContext; 57 | //工程路径 58 | String projectBasePath="/Users/admin/eclipse-workspace/projectName"; 59 | //包路径 60 | String packagePathUrl="com.ruoyi.system.mapper"; 61 | 62 | //包含生成文件的类型,目前包含的 63 | TjNewMap includeType=TjNewMap.newInstance(); 64 | //选择所需要生成的内容:1:entity 2 mainMapper 4 service 5:dao 6:extdao 7:mapper 65 | //includeType.putCon("1","2","3","4","5","6","7");//1:entity 2 mainMapper 4 service 5:dao 6:extdao 7:mapper 66 | includeType.putConMutil("1","2","4","5","6","7"); 67 | //添加数据库表 68 | List tableList=Lists.newArrayList(); 69 | tableList.add("sys_notice"); 70 | GenCodeTool gtc=new GenCodeTool( projectBasePath, tableList, includeType); 71 | gtc.setPackagePathUrl(packagePathUrl); 72 | try { 73 | gtc.startGen(); 74 | } catch (Exception e) { 75 | e.printStackTrace(); 76 | } 77 | } 78 | } 79 | 80 | 直接执行该junit,即可生成到指定项目路径下相关类。 81 | 82 | 4、如果是对现有项目的某些功能改造,如何改造以及案例说明,请参考csdn文章:https://blog.csdn.net/kevin_liang_feng/article/details/103337851 83 | 84 | 5、另外,我们的mapper是主子结构,即子mapper继承主mapper,主mapper就是根据数据库表生成的mapper文件,子mapper是用来手工增加方法的,这样当数据库变化时,直接覆盖主mapper即可,但是目前为止 ,我们还没有需要手工增加方法的必要,同时dao层也是与mapper文件对应的继承关系 85 | 生成的代码中, 86 | 有一个实体: 87 | public class SysNotice extends TjBaseEntity 88 | 两个dao: 89 | @MyBatisDao 90 | public interface SysNoticeDao extends SysNoticeMainDao 91 | @MyBatisDao 92 | public interface SysNoticeMainDao extends CrudDao 93 | 一个service: 94 | @Service 95 | @Transactional(readOnly = true) 96 | public class SysNoticeService extends CrudService 97 | 两个mapper: 98 | SysNoticeDao.xml 99 | SysNoticeMainDao.xml 100 | 101 | 最后: 102 | 本项目的演变过程,请参考:https://blog.csdn.net/kevin_liang_feng/article/details/103014240 103 | 104 | 如何用对现有项目改造增加动态sql和动态bean,请参考:https://blog.csdn.net/kevin_liang_feng/article/details/103337851 105 | -------------------------------------------------------------------------------- /gencode-base/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/gencode-base/.DS_Store -------------------------------------------------------------------------------- /gencode-base/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /gencode-base/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /gencode-base/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | gencode-base 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jdt.core.javanature 26 | org.eclipse.m2e.core.maven2Nature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | 29 | 30 | -------------------------------------------------------------------------------- /gencode-base/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /gencode-base/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 8 | org.eclipse.jdt.core.compiler.release=disabled 9 | org.eclipse.jdt.core.compiler.source=1.8 10 | -------------------------------------------------------------------------------- /gencode-base/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /gencode-base/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /gencode-base/src/main/java/com/tengjie/common/gencode/tools/BackstageGenCode.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.gencode.tools; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.List; 8 | import java.util.Map; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | 12 | import org.springframework.stereotype.Service; 13 | 14 | import com.google.common.collect.Lists; 15 | import com.tengjie.common.gencode.GenUtils; 16 | import com.tengjie.common.gencode.vo.TableColumn; 17 | import com.tengjie.common.gencode.vo.TableMetadata; 18 | import com.tengjie.common.persistence.ConditionBean; 19 | import com.tengjie.common.persistence.JoinTableBean; 20 | 21 | import com.tengjie.common.utils.ListUtils; 22 | import com.tengjie.common.utils.MapUtils; 23 | import com.tengjie.common.utils.MyStringBuffer; 24 | import com.tengjie.common.utils.Reflections; 25 | import com.tengjie.common.utils.StringUtils; 26 | 27 | /** 28 | * 生成代码部分 29 | * @author liangfeng 30 | * 31 | */ 32 | 33 | public class BackstageGenCode extends InterfaceAndBackstageFactory { 34 | 35 | 36 | 37 | /** 38 | * 根据 业务表生成动态共用查询部分,busiinterId实际就是tb_management_backstage表的id 39 | * @throws Exception 40 | */ 41 | public String genDynaQuery(List queryAreaList,List listDataShowList,String mainTableName) throws Exception{ 42 | MyStringBuffer sb=new MyStringBuffer(); 43 | 44 | TableMetadata actualTm=GenUtils.buildTableMetadataBydbTableName(mainTableName); 45 | 46 | sb.append(findControllerMethodDefine_code(actualTm,"genDynaQuery","HttpServletRequest request"),"{"); 47 | sb.insertBlankLine(); 48 | // sb.appendK(actualTm.getTableNameFirstUp(false),"=",actualTm.getTableNameFirstUp(false),".initDynaMap(request);"); 49 | String paramName=actualTm.getTableNameFirstUp(false);//主变量名称 50 | sb.append(paramName+"="+paramName+".initDynaMap(request);"+HUANHANG); 51 | sb.insertBlankLine(); 52 | 53 | //处理显示列表区 54 | 55 | 56 | sb.appendK("return ",paramName,";"); 57 | sb.append("}"); 58 | sb.insertBlankLine(); 59 | 60 | return sb.toString(); 61 | } 62 | 63 | 64 | /** 65 | * 根据业务表id生成controller,只有busiinterId为空的时候,说明是调用的fastgenMapperAndBean执行,这时需要projectId\mainTableName不为空 66 | * 否则如果busiinterId不为空,则实际不需要projectId\mainTableName 67 | * @param busiinterId:tb_management_backstage表的id 68 | * @throws Exception 69 | */ 70 | public String genListController(String mainTableName) throws Exception{ 71 | String tbTableName=StringUtils.toCamelCase(mainTableName); 72 | List queryAreaList=MapUtils.mapToList(DBTool.getAllTableField().get(tbTableName), false); 73 | List outPutList=MapUtils.mapToList(DBTool.getAllTableField().get(tbTableName), false); 74 | 75 | return genDynaQuery(queryAreaList,outPutList, mainTableName); 76 | } 77 | 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /gencode-base/src/main/java/com/tengjie/common/gencode/vo/Dict.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.gencode.vo; 2 | 3 | import javax.validation.constraints.NotNull; 4 | import javax.xml.bind.annotation.XmlAttribute; 5 | 6 | import org.hibernate.validator.constraints.Length; 7 | 8 | 9 | /** 10 | * 字典Entity 11 | * @author 12 | * @version 2013-05-15 13 | */ 14 | public class Dict { 15 | 16 | private static final long serialVersionUID = 1L; 17 | private String value; // 数据值 18 | private String label; // 标签名 19 | private String type; // 类型 20 | private String description;// 描述 21 | private Integer sort; // 排序 22 | private String parentId;//父Id 23 | 24 | public Dict() { 25 | super(); 26 | } 27 | 28 | public Dict(String value, String label){ 29 | this.value = value; 30 | this.label = label; 31 | } 32 | 33 | @XmlAttribute 34 | @Length(min=1, max=100) 35 | public String getValue() { 36 | return value; 37 | } 38 | 39 | public void setValue(String value) { 40 | this.value = value; 41 | } 42 | 43 | @XmlAttribute 44 | @Length(min=1, max=100) 45 | public String getLabel() { 46 | return label; 47 | } 48 | 49 | public void setLabel(String label) { 50 | this.label = label; 51 | } 52 | 53 | @Length(min=1, max=100) 54 | public String getType() { 55 | return type; 56 | } 57 | 58 | public void setType(String type) { 59 | this.type = type; 60 | } 61 | 62 | @XmlAttribute 63 | @Length(min=0, max=100) 64 | public String getDescription() { 65 | return description; 66 | } 67 | 68 | public void setDescription(String description) { 69 | this.description = description; 70 | } 71 | 72 | @NotNull 73 | public Integer getSort() { 74 | return sort; 75 | } 76 | 77 | public void setSort(Integer sort) { 78 | this.sort = sort; 79 | } 80 | 81 | @Length(min=1, max=100) 82 | public String getParentId() { 83 | return parentId; 84 | } 85 | 86 | public void setParentId(String parentId) { 87 | this.parentId = parentId; 88 | } 89 | 90 | @Override 91 | public String toString() { 92 | return label; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /gencode-base/src/main/java/com/tengjie/common/gencode/vo/GenConfig.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2015-2020 GenPLus All rights reserved. 3 | */ 4 | package com.tengjie.common.gencode.vo; 5 | 6 | import java.io.Serializable; 7 | import java.util.List; 8 | 9 | import javax.xml.bind.annotation.XmlElement; 10 | import javax.xml.bind.annotation.XmlElementWrapper; 11 | import javax.xml.bind.annotation.XmlRootElement; 12 | 13 | 14 | 15 | /** 16 | * 生成方案Entity 17 | * @author sjjt 18 | * @version 2017-5-15 19 | */ 20 | @XmlRootElement(name="config") 21 | public class GenConfig implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | private List categoryList; // 代码模板分类 25 | private List javaTypeList; // Java类型 26 | private List queryTypeList; // 查询类型 27 | private List showTypeList; // 显示类型 28 | 29 | public GenConfig() { 30 | super(); 31 | } 32 | 33 | @XmlElementWrapper(name = "category") 34 | @XmlElement(name = "dict") 35 | public List getCategoryList() { 36 | return categoryList; 37 | } 38 | 39 | public void setCategoryList(List categoryList) { 40 | this.categoryList = categoryList; 41 | } 42 | 43 | @XmlElementWrapper(name = "javaType") 44 | @XmlElement(name = "dict") 45 | public List getJavaTypeList() { 46 | return javaTypeList; 47 | } 48 | 49 | public void setJavaTypeList(List javaTypeList) { 50 | this.javaTypeList = javaTypeList; 51 | } 52 | 53 | @XmlElementWrapper(name = "queryType") 54 | @XmlElement(name = "dict") 55 | public List getQueryTypeList() { 56 | return queryTypeList; 57 | } 58 | 59 | public void setQueryTypeList(List queryTypeList) { 60 | this.queryTypeList = queryTypeList; 61 | } 62 | 63 | @XmlElementWrapper(name = "showType") 64 | @XmlElement(name = "dict") 65 | public List getShowTypeList() { 66 | return showTypeList; 67 | } 68 | 69 | public void setShowTypeList(List showTypeList) { 70 | this.showTypeList = showTypeList; 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /gencode-base/src/main/java/com/tengjie/common/gencode/vo/TableMetadata.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.gencode.vo; 2 | 3 | import org.hibernate.validator.constraints.Length; 4 | 5 | import com.tengjie.common.utils.StringUtils; 6 | 7 | /** 8 | * TB_TABLE_METADATAEntity 9 | * 10 | */ 11 | public class TableMetadata { 12 | 13 | private static final long serialVersionUID = 1L; 14 | private String tableName; // 工作时间 15 | private String tableChineseName; // 中文名 16 | private String tableDesc; // 业务描述 17 | private String primaryKeyName; // 主键名 18 | public static String _TB_TABLE_NAME_="tbTableMetadata"; 19 | public static String _TABLENAME="tableName"; // 工作时间 20 | public static String _TABLECHINESENAME="tableChineseName"; // 中文名 21 | public static String _TABLEDESC="tableDesc"; // 业务描述 22 | public static String _PROJECTID="projectId"; // project_id 23 | 24 | public TableMetadata() { 25 | super(); 26 | } 27 | 28 | @Length(min=1, max=100, message="工作时间长度必须介于 1 和 100 之间") 29 | public String getTableName() { 30 | return tableName; 31 | } 32 | 33 | public String getTableNameFirstUp(boolean bl) { 34 | String step1=tableName.toLowerCase().contains("tb_")?tableName.toLowerCase().substring(3):tableName; 35 | String step2=""; 36 | if(bl){ 37 | step2=StringUtils.toCapitalizeCamelCase(step1); 38 | }else{ 39 | step2=StringUtils.toCamelCase(step1); 40 | } 41 | 42 | return step2; 43 | } 44 | public void setTableName(String tableName) { 45 | this.tableName = tableName; 46 | } 47 | 48 | @Length(min=1, max=100, message="中文名长度必须介于 1 和 100 之间") 49 | public String getTableChineseName() { 50 | return tableChineseName; 51 | } 52 | 53 | public void setTableChineseName(String tableChineseName) { 54 | this.tableChineseName = tableChineseName; 55 | } 56 | 57 | @Length(min=1, max=300, message="业务描述长度必须介于 1 和 300 之间") 58 | public String getTableDesc() { 59 | return tableDesc; 60 | } 61 | 62 | public void setTableDesc(String tableDesc) { 63 | this.tableDesc = tableDesc; 64 | } 65 | 66 | 67 | 68 | public String getPrimaryKeyName() { 69 | return primaryKeyName; 70 | } 71 | 72 | public void setPrimaryKeyName(String primaryKeyName) { 73 | this.primaryKeyName = primaryKeyName; 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /gencode-base/src/main/java/com/tengjie/common/utils/freemarker/GenTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2015-2020 GenPLus All rights reserved. 3 | */ 4 | package com.tengjie.common.utils.freemarker; 5 | 6 | import java.util.List; 7 | 8 | import javax.xml.bind.annotation.XmlRootElement; 9 | import javax.xml.bind.annotation.XmlTransient; 10 | 11 | import org.hibernate.validator.constraints.Length; 12 | 13 | import com.google.common.collect.Lists; 14 | 15 | import com.tengjie.common.utils.StringUtils; 16 | 17 | 18 | /** 19 | * 生成方案Entity 20 | * @author sjjt 21 | * @version 2017-5-15 22 | */ 23 | @XmlRootElement(name="template") 24 | public class GenTemplate { 25 | 26 | private static final long serialVersionUID = 1L; 27 | private String name; // 名称 28 | private String category; // 分类 29 | private String filePath; // 生成文件路径 30 | private String fileName; // 文件名 31 | private String content; // 内容 32 | 33 | public GenTemplate() { 34 | super(); 35 | } 36 | 37 | 38 | @Length(min=1, max=200) 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public void setName(String name) { 44 | this.name = name; 45 | } 46 | 47 | public String getFileName() { 48 | return fileName; 49 | } 50 | 51 | public void setFileName(String fileName) { 52 | this.fileName = fileName; 53 | } 54 | 55 | public String getFilePath() { 56 | return filePath; 57 | } 58 | 59 | public void setFilePath(String filePath) { 60 | this.filePath = filePath; 61 | } 62 | 63 | public String getContent() { 64 | return content; 65 | } 66 | 67 | public void setContent(String content) { 68 | this.content = content; 69 | } 70 | 71 | public String getCategory() { 72 | return category; 73 | } 74 | 75 | public void setCategory(String category) { 76 | this.category = category; 77 | } 78 | 79 | @XmlTransient 80 | public List getCategoryList() { 81 | if (category == null){ 82 | return Lists.newArrayList(); 83 | }else{ 84 | return Lists.newArrayList(StringUtils.split(category, ",")); 85 | } 86 | } 87 | 88 | public void setCategoryList(List categoryList) { 89 | if (categoryList == null){ 90 | this.category = ""; 91 | }else{ 92 | this.category = ","+StringUtils.join(categoryList, ",") + ","; 93 | } 94 | } 95 | 96 | } 97 | 98 | 99 | -------------------------------------------------------------------------------- /gencode-base/src/main/resources/modules/gen/config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /gencode-base/src/main/resources/modules/gen/curd/service.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gencode-base/src/main/resources/modules/gen/curd/serviceMany.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gencode-base/src/main/resources/modules/gen/dao/dao.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gencode-base/src/main/resources/modules/gen/dao/entity.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gencode-base/src/main/resources/modules/gen/dao/extDao.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gencode-base/src/main/resources/modules/gen/dao/extMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /gencode-base/src/test/java/gencode/gencode/AppTest.java: -------------------------------------------------------------------------------- 1 | package gencode.gencode; 2 | 3 | import junit.framework.Test; 4 | import junit.framework.TestCase; 5 | import junit.framework.TestSuite; 6 | 7 | /** 8 | * Unit test for simple App. 9 | */ 10 | public class AppTest 11 | extends TestCase 12 | { 13 | /** 14 | * Create the test case 15 | * 16 | * @param testName name of the test case 17 | */ 18 | public AppTest( String testName ) 19 | { 20 | super( testName ); 21 | } 22 | 23 | /** 24 | * @return the suite of tests being tested 25 | */ 26 | public static Test suite() 27 | { 28 | return new TestSuite( AppTest.class ); 29 | } 30 | 31 | /** 32 | * Rigourous Test :-) 33 | */ 34 | public void testApp() 35 | { 36 | assertTrue( true ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tengjie-base/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/.DS_Store -------------------------------------------------------------------------------- /tengjie-base/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /tengjie-base/.externalToolBuilders/org.eclipse.wst.validation.validationbuilder (6).launch: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /tengjie-base/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /tengjie-base/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | tengjie-base 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.ui.externaltools.ExternalToolBuilder 20 | full,incremental, 21 | 22 | 23 | LaunchConfigHandle 24 | <project>/.externalToolBuilders/org.eclipse.wst.validation.validationbuilder (6).launch 25 | 26 | 27 | 28 | 29 | org.eclipse.wst.validation.validationbuilder 30 | 31 | 32 | 33 | 34 | org.eclipse.m2e.core.maven2Builder 35 | 36 | 37 | 38 | 39 | 40 | org.eclipse.jdt.core.javanature 41 | org.eclipse.m2e.core.maven2Nature 42 | org.eclipse.wst.common.project.facet.core.nature 43 | 44 | 45 | -------------------------------------------------------------------------------- /tengjie-base/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /tengjie-base/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.8 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 12 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 13 | org.eclipse.jdt.core.compiler.release=disabled 14 | org.eclipse.jdt.core.compiler.source=1.8 15 | -------------------------------------------------------------------------------- /tengjie-base/.settings/org.eclipse.jdt.ui.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.ui.text.custom_code_templates= 3 | -------------------------------------------------------------------------------- /tengjie-base/.settings/org.eclipse.ltk.core.refactoring.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false 3 | -------------------------------------------------------------------------------- /tengjie-base/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /tengjie-base/.settings/org.eclipse.m2e.wtp.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.m2e.wtp.enabledProjectSpecificPrefs=false 3 | -------------------------------------------------------------------------------- /tengjie-base/.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /tengjie-base/.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | DELEGATES_PREFERENCE=delegateValidatorList 2 | USER_BUILD_PREFERENCE=enabledBuildValidatorList 3 | USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator; 4 | USER_PREFERENCE=overrideGlobalPreferencestruedisableAllValidationfalseversion1.2.701.v201810290944 5 | disabled=06target 6 | eclipse.preferences.version=1 7 | override=true 8 | suspend=false 9 | vals/com.ibm.etools.aries.core.ApplicationManifestValidator/global=FF02 10 | vals/com.ibm.etools.aries.core.CompositeBundleManifestValidator/global=FF02 11 | vals/com.ibm.etools.aries.core.DeploymentManifestValidator/global=FF02 12 | vals/com.ibm.etools.aries.core.MavenConflictValidator/global=FF02 13 | vals/com.ibm.etools.aries.core.SubsystemManifestValidator/global=FF02 14 | vals/com.ibm.ws.st.configuration.validator/global=FF02 15 | vals/com.ibm.ws.st.jee.configuration.validator/global=FF02 16 | vals/org.eclipse.jst.jsf.facelet.ui.FaceletHTMLValidator/global=FF01 17 | vals/org.eclipse.jst.jsf.ui.JSFAppConfigValidator/global=FF01 18 | vals/org.eclipse.jst.jsp.core.JSPBatchValidator/global=FF01 19 | vals/org.eclipse.jst.jsp.core.JSPContentValidator/global=FF01 20 | vals/org.eclipse.jst.jsp.core.TLDValidator/global=FF01 21 | vals/org.eclipse.wst.dtd.core.dtdDTDValidator/global=FF01 22 | vals/org.eclipse.wst.html.core.HTMLValidator/global=FF01 23 | vals/org.eclipse.wst.json.core.json/global=FF03 24 | vals/org.eclipse.wst.wsdl.validation.wsdl/global=FF02158org.eclipse.wst.wsdl.validation.internal.eclipse.Validator 25 | vals/org.eclipse.wst.xml.core.xml/global=FF03 26 | vals/org.eclipse.wst.xsd.core.xsd/global=FF02162org.eclipse.wst.xsd.core.internal.validation.eclipse.Validator 27 | vals/org.eclipse.wst.xsl.core.xsl/global=FF02 28 | vf.version=3 29 | -------------------------------------------------------------------------------- /tengjie-base/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-2030, topspeed (79638655@qq.com). 2 |

3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 | use this file except in compliance with the License. You may obtain a copy of 5 | the License at 6 |

7 | https://www.apache.org/licenses/LICENSE-2.0 8 |

9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | License for the specific language governing permissions and limitations under 13 | the License. 14 | 15 | -------------------------------------------------------------------------------- /tengjie-base/doc/spring-evel解释: -------------------------------------------------------------------------------- 1 | 2 | 这个eval与普通el表达式的区别是: 3 | 实际eval就是相当月${},只不过放到eval中就不需要加这个${}了,即 4 | 5 | 但是,当这个tableDataEle.attrMap['tjText'].attrCovertValue的内容本身就是一个el表达式呢? 6 | 这个实际就相当于在返回的表达式外再加一个${},就相当于动态运行表达式了!!!,所以是很有价值的。 7 | 也可以用这种混合模式: 8 | 9 | ${dynamicJspListConfigVO.dynamicModelName}部分是动态,假设他的值是aa,结果相当于 10 | ${aa[tableDataEle.attrMap['tjText'].attrName]} -------------------------------------------------------------------------------- /tengjie-base/doc/程序隐藏加密权限描述.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/doc/程序隐藏加密权限描述.docx -------------------------------------------------------------------------------- /tengjie-base/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/.DS_Store -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/java/com/tengjie/.DS_Store -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/java/com/tengjie/common/.DS_Store -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/beanvalidator/BeanValidators.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.beanvalidator; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | import javax.validation.ConstraintViolation; 8 | import javax.validation.ConstraintViolationException; 9 | import javax.validation.Validator; 10 | 11 | import net.sf.cglib.core.DefaultGeneratorStrategy; 12 | 13 | import com.google.common.collect.Lists; 14 | import com.google.common.collect.Maps; 15 | 16 | /** 17 | * JSR303 Validator(Hibernate Validator)工具类. 18 | * 19 | * ConstraintViolation中包含propertyPath, message 和invalidValue等信息. 20 | * 提供了各种convert方法,适合不同的i18n需求: 21 | * 1. List, String内容为message 22 | * 2. List, String内容为propertyPath + separator + message 23 | * 3. Map 24 | * 25 | * @author 26 | * @version 2013-01-15 27 | */ 28 | public class BeanValidators { 29 | 30 | /** 31 | * 调用JSR303的validate方法, 验证失败时抛出ConstraintViolationException. 32 | */ 33 | @SuppressWarnings({ "unchecked", "rawtypes" }) 34 | public static void validateWithException(Validator validator, Object object, Class... groups) 35 | throws ConstraintViolationException { 36 | Set constraintViolations = validator.validate(object, groups); 37 | if (!constraintViolations.isEmpty()) { 38 | throw new ConstraintViolationException(constraintViolations); 39 | } 40 | } 41 | 42 | /** 43 | * 辅助方法, 转换ConstraintViolationException中的Set中为List. 44 | */ 45 | public static List extractMessage(ConstraintViolationException e) { 46 | return extractMessage(e.getConstraintViolations()); 47 | } 48 | 49 | /** 50 | * 辅助方法, 转换Set为List 51 | */ 52 | @SuppressWarnings("rawtypes") 53 | public static List extractMessage(Set constraintViolations) { 54 | List errorMessages = Lists.newArrayList(); 55 | for (ConstraintViolation violation : constraintViolations) { 56 | errorMessages.add(violation.getMessage()); 57 | } 58 | return errorMessages; 59 | } 60 | 61 | /** 62 | * 辅助方法, 转换ConstraintViolationException中的Set为Map. 63 | */ 64 | public static Map extractPropertyAndMessage(ConstraintViolationException e) { 65 | return extractPropertyAndMessage(e.getConstraintViolations()); 66 | } 67 | 68 | /** 69 | * 辅助方法, 转换Set为Map. 70 | */ 71 | @SuppressWarnings("rawtypes") 72 | public static Map extractPropertyAndMessage(Set constraintViolations) { 73 | Map errorMessages = Maps.newHashMap(); 74 | for (ConstraintViolation violation : constraintViolations) { 75 | errorMessages.put(violation.getPropertyPath().toString(), violation.getMessage()); 76 | } 77 | return errorMessages; 78 | } 79 | 80 | /** 81 | * 辅助方法, 转换ConstraintViolationException中的Set为List. 82 | */ 83 | public static List extractPropertyAndMessageAsList(ConstraintViolationException e) { 84 | return extractPropertyAndMessageAsList(e.getConstraintViolations(), " "); 85 | } 86 | 87 | /** 88 | * 辅助方法, 转换Set为List. 89 | */ 90 | @SuppressWarnings("rawtypes") 91 | public static List extractPropertyAndMessageAsList(Set constraintViolations) { 92 | return extractPropertyAndMessageAsList(constraintViolations, " "); 93 | } 94 | 95 | /** 96 | * 辅助方法, 转换ConstraintViolationException中的Set为List. 97 | */ 98 | public static List extractPropertyAndMessageAsList(ConstraintViolationException e, String separator) { 99 | return extractPropertyAndMessageAsList(e.getConstraintViolations(), separator); 100 | } 101 | 102 | /** 103 | * 辅助方法, 转换Set为List. 104 | */ 105 | @SuppressWarnings("rawtypes") 106 | public static List extractPropertyAndMessageAsList(Set constraintViolations, 107 | String separator) { 108 | List errorMessages = Lists.newArrayList(); 109 | for (ConstraintViolation violation : constraintViolations) { 110 | errorMessages.add(violation.getPropertyPath() + separator + violation.getMessage()); 111 | } 112 | return errorMessages; 113 | } 114 | } -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/mapper/BeanMapper.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.mapper; 2 | 3 | import java.util.Collection; 4 | import java.util.List; 5 | 6 | import org.dozer.DozerBeanMapper; 7 | 8 | import com.google.common.collect.Lists; 9 | 10 | /** 11 | * 简单封装Dozer, 实现深度转换Bean<->Bean的Mapper.实现: 12 | * 13 | * 1. 持有Mapper的单例. 14 | * 2. 返回值类型转换. 15 | * 3. 批量转换Collection中的所有对象. 16 | * 4. 区分创建新的B对象与将对象A值复制到已存在的B对象两种函数. 17 | * 18 | * @author 19 | * @version 2013-01-15 20 | */ 21 | public class BeanMapper { 22 | 23 | /** 24 | * 持有Dozer单例, 避免重复创建DozerMapper消耗资源. 25 | */ 26 | private static DozerBeanMapper dozer = new DozerBeanMapper(); 27 | 28 | /** 29 | * 基于Dozer转换对象的类型. 30 | */ 31 | public static T map(Object source, Class destinationClass) { 32 | return dozer.map(source, destinationClass); 33 | } 34 | 35 | /** 36 | * 基于Dozer转换Collection中对象的类型. 37 | */ 38 | @SuppressWarnings("rawtypes") 39 | public static List mapList(Collection sourceList, Class destinationClass) { 40 | List destinationList = Lists.newArrayList(); 41 | for (Object sourceObject : sourceList) { 42 | T destinationObject = dozer.map(sourceObject, destinationClass); 43 | destinationList.add(destinationObject); 44 | } 45 | return destinationList; 46 | } 47 | 48 | /** 49 | * 基于Dozer将对象A的值拷贝到对象B中. 50 | */ 51 | public static void copy(Object source, Object destinationObject) { 52 | dozer.map(source, destinationObject); 53 | } 54 | } -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/mapper/ConvertBlobTypeHandler.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.mapper; 2 | 3 | 4 | import java.io.ByteArrayInputStream; 5 | import java.io.UnsupportedEncodingException; 6 | import java.sql.Blob; 7 | import java.sql.CallableStatement; 8 | import java.sql.PreparedStatement; 9 | import java.sql.ResultSet; 10 | import java.sql.SQLException; 11 | 12 | import org.apache.ibatis.type.BaseTypeHandler; 13 | import org.apache.ibatis.type.JdbcType; 14 | import org.apache.ibatis.type.MappedJdbcTypes; 15 | 16 | /** 17 | * className:ConvertBlobTypeHandler 18 | * 19 | * 自定义typehandler,解决mybatis存储blob字段后,出现乱码的问题 20 | * 配置mapper.xml: 21 | * 22 | * 23 | * @author 24 | * @version 1.0.0 25 | * @date 2016-05-05 11:15:23 26 | * 27 | */ 28 | @MappedJdbcTypes(JdbcType.BLOB) 29 | public class ConvertBlobTypeHandler extends BaseTypeHandler {//指定字符集 30 | private static final String DEFAULT_CHARSET = "utf-8"; 31 | 32 | @Override 33 | public void setNonNullParameter(PreparedStatement ps, int i, 34 | String parameter, JdbcType jdbcType) throws SQLException { 35 | ByteArrayInputStream bis; 36 | try { 37 | bis = new ByteArrayInputStream(parameter.getBytes(DEFAULT_CHARSET)); 38 | } catch (UnsupportedEncodingException e) { 39 | throw new RuntimeException("Blob Encoding Error!"); 40 | } 41 | ps.setBinaryStream(i, bis, parameter.length()); 42 | } 43 | 44 | @Override 45 | public String getNullableResult(ResultSet rs, String columnName) 46 | throws SQLException { 47 | Blob blob = rs.getBlob(columnName); 48 | byte[] returnValue = null; 49 | if (null != blob) { 50 | returnValue = blob.getBytes(1, (int) blob.length()); 51 | } else{ 52 | return rs.getString(columnName); 53 | } 54 | try { 55 | return new String(returnValue, DEFAULT_CHARSET); 56 | } catch (UnsupportedEncodingException e) { 57 | throw new RuntimeException("Blob Encoding Error!"); 58 | } 59 | } 60 | 61 | @Override 62 | public String getNullableResult(CallableStatement cs, int columnIndex) 63 | throws SQLException { 64 | Blob blob = cs.getBlob(columnIndex); 65 | byte[] returnValue = null; 66 | if (null != blob) { 67 | returnValue = blob.getBytes(1, (int) blob.length()); 68 | } 69 | try { 70 | return new String(returnValue, DEFAULT_CHARSET); 71 | } catch (UnsupportedEncodingException e) { 72 | throw new RuntimeException("Blob Encoding Error!"); 73 | } 74 | } 75 | 76 | @Override 77 | public String getNullableResult(ResultSet arg0, int arg1) throws SQLException { 78 | // TODO Auto-generated method stub 79 | return null; 80 | } } 81 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/java/com/tengjie/common/persistence/.DS_Store -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/AppendAutoPutCB.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.commons.lang3.StringUtils; 6 | 7 | import com.tengjie.common.persistence.util.MybatisSqlGetTool; 8 | import com.tengjie.common.utils.Reflections; 9 | 10 | /** 11 | * queryDataMappedFieldList.putAppendField("childList", List.class).putFieldCallBack("childList", this, "dealFindChildList"); 12 | * 正常这样写比较麻烦,可以直接变为 queryDataMappedFieldList.putAppendField("childList", List.class).putFieldCallBack("dealFindChildList"); 13 | * @author liangfeng 14 | * 15 | */ 16 | public class AppendAutoPutCB { 17 | private TjBaseEntity be; 18 | private String callBackFieldName; 19 | private Object currObj; 20 | public AppendAutoPutCB(TjBaseEntity be, String callBackFieldName) { 21 | super(); 22 | this.be = be; 23 | this.callBackFieldName = callBackFieldName; 24 | } 25 | 26 | public AppendAutoPutCB(TjBaseEntity be, Object currObj,String callBackFieldName) { 27 | super(); 28 | this.be = be; 29 | this.currObj = currObj; 30 | this.callBackFieldName = callBackFieldName; 31 | } 32 | /** 33 | * 添加处理该字段的回调 34 | * @param methodName 35 | * @return 36 | */ 37 | public T putFieldCallBack(String methodName){ 38 | return be.putFieldCallBack(callBackFieldName, currObj, methodName); 39 | 40 | } 41 | 42 | public TjBaseEntity getBe() { 43 | return be; 44 | } 45 | public void setBe(TjBaseEntity be) { 46 | this.be = be; 47 | } 48 | public String getCallBackFieldName() { 49 | return callBackFieldName; 50 | } 51 | public void setCallBackFieldName(String callBackFieldName) { 52 | this.callBackFieldName = callBackFieldName; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/BaseDao.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence; 2 | 3 | /** 4 | * DAO支持类实现 5 | * @author 6 | * @version 2014-05-16 7 | */ 8 | public interface BaseDao { 9 | 10 | } -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/ConditionBean.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence; 2 | 3 | import java.io.Serializable; 4 | 5 | public class ConditionBean implements Serializable { 6 | private static final long serialVersionUID = 1L; 7 | public static final String SIGN_EQUAL = " = "; 8 | public static final String SIGN_NOT_EQUAL = " != "; 9 | public static final String SIGN_BETWEEN = " between "; 10 | public static final String SIGN_BIG= " > "; 11 | public static final String SIGN_BIG_EQUAL = " >= "; 12 | public static final String SIGN_SMALL = " < "; 13 | public static final String SIGN_SMALL_EQUAL = " <= "; 14 | public static final String SIGN_IS_NULL = " is null "; 15 | public static final String SIGN_IS_NOT_NULL = " is not null "; 16 | public static final String SIGN_IN = " in "; 17 | public static final String SIGN_LIKE = " like "; 18 | 19 | protected String sign=SIGN_EQUAL;//运算符,可不写,默认是SIGN_EQUAL 20 | 21 | public String getSign() { 22 | return sign; 23 | } 24 | 25 | public void setSign(String sign) { 26 | this.sign = sign; 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/CrudDao.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | /** 9 | * DAO支持类实现 10 | * @author 11 | * @version 2014-05-16 12 | * @param 13 | */ 14 | public interface CrudDao extends BaseDao { 15 | 16 | /** 17 | * 获取单条数据 18 | * @param id 19 | * @return 20 | */ 21 | public T get(String id); 22 | 23 | /** 24 | * 获取单条数据 25 | * @param entity 26 | * @return 27 | */ 28 | public T get(T entity); 29 | /** 30 | * 获取单条数据,entity中的有值数据会作为查询条件,若返回多条则会抛出业务异常 31 | * @param entity 32 | * @return 33 | */ 34 | public T getByWhere(T entity); 35 | 36 | /** 37 | * 获取单条数据 38 | * @param entity 39 | * @return 40 | */ 41 | public T getNew(T entity); 42 | /** 43 | * 根据实体名称和字段名称和字段值获取唯一记录 44 | * 45 | * @param 46 | * @param propertyName 47 | * @param value 48 | * @return 49 | */ 50 | public T findUniqueByProperty(@Param(value = "propertyName") String propertyName, @Param(value = "value") Object value); 51 | /** 52 | * 根据实体名称和字段名称和字段值获取list记录 53 | * 54 | * @param 55 | * @param propertyName 56 | * @param value 57 | * @return 58 | */ 59 | public List findListByProperty(@Param(value = "propertyName") String propertyName, @Param(value = "value") Object value); 60 | /** 61 | * 更新实体中某一个字段的值(目前还不知道是否能更新日期类型,待测试) 62 | * @param updatePropertyName 63 | * @param updateValue 64 | * @param wherePropertyName 65 | * @return whereValue 66 | */ 67 | public int updateForOneProperty(@Param(value = "updatePropertyName") String updatePropertyName, @Param(value = "updateValue") Object updateValue,@Param(value = "wherePropertyName") String wherePropertyName,@Param(value = "whereValue") Object whereValue); 68 | 69 | /** 70 | * 根据一个属性名,删除记录 71 | * 72 | * @param 73 | * @param propertyName 74 | * @param value 75 | * @return 76 | */ 77 | public int deleteByOneProperty(@Param(value = "propertyName") String propertyName, @Param(value = "value") Object value); 78 | 79 | /** 80 | * 查询数据列表,如果需要分页,请设置分页对象,如:entity.setPage(new Page()); 81 | * @param entity 82 | * @return 83 | */ 84 | public List findList(T entity); 85 | 86 | 87 | 88 | 89 | /** 90 | * 查询所有数据列表 91 | * @param entity 92 | * @return 93 | */ 94 | public List findAllList(T entity); 95 | 96 | /** 97 | * 查询所有数据列表 98 | * @see public List findAllList(T entity) 99 | * @return 100 | */ 101 | @Deprecated 102 | public List findAllList(); 103 | 104 | /** 105 | * 插入数据 106 | * @param entity 107 | * @return 108 | */ 109 | public int insert(T entity); 110 | 111 | /** 112 | * 更新数据,注意直接调用dao,不会更新updateDate字段,若调用service则会更新 113 | * @param entity 114 | * @return 115 | */ 116 | public int update(T entity); 117 | /** 118 | * 更新数据,实体bean中的updateWhereConditionMap若包含该属性,并且该属性不为空则会拼接到update的where条件中 119 | * @param entity 120 | * @return 121 | */ 122 | public int updateByWhere(T entity); 123 | 124 | /** 125 | * 删除数据(物理删除,从数据库中彻底删除) 126 | * @param id 127 | * @see public int delete(T entity) 128 | * @return 129 | */ 130 | @Deprecated 131 | public int delete(String id); 132 | 133 | /** 134 | * 删除数据(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏) 135 | * @param id 136 | * @see public int delete(T entity) 137 | * @return 138 | */ 139 | @Deprecated 140 | public int deleteByLogic(String id); 141 | 142 | /** 143 | * 删除数据(物理删除,从数据库中彻底删除) 144 | * @param entity 145 | * @return 146 | */ 147 | public int delete(T entity); 148 | 149 | /** 150 | * 删除数据(逻辑删除,更新del_flag字段为1,在表包含字段del_flag时,可以调用此方法,将数据隐藏) 151 | * @param entity 152 | * @return 153 | */ 154 | public int deleteByLogic(T entity); 155 | /** 156 | * 分组查询 157 | * @param entity 158 | * @return 159 | */ 160 | public List findGroupByList(T entity); 161 | /** 162 | * 批量删除 163 | * @param list 164 | * @return 165 | */ 166 | public int insertBatch(List list); 167 | 168 | /** 169 | * 完全手写查询,任意的sql语句,可以传参也可以不传 170 | * @param entity 171 | * @return 172 | */ 173 | public List findAnyQuery(T entity); 174 | /** 175 | * 完全手写查询,任意的sql语句,可以传参也可以不传 176 | * @param entity 177 | * @return 178 | */ 179 | public int updateAnySql(T entity); 180 | } -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/CustMySqlSchemaStatVisitor.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.alibaba.druid.sql.ast.statement.SQLExprTableSource; 7 | import com.alibaba.druid.sql.ast.statement.SQLTableSource; 8 | import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter; 9 | import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlSchemaStatVisitor; 10 | 11 | public class CustMySqlSchemaStatVisitor extends MySqlSchemaStatVisitor { 12 | private Map aliasMap = new HashMap(); 13 | public boolean visit(SQLExprTableSource x) { 14 | String alias = x.getAlias(); 15 | aliasMap.put(alias, x.getName().getSimpleName()); 16 | return true; 17 | } 18 | 19 | public Map getAliasMap() { 20 | return aliasMap; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/DataEntityFieldCallBackBean.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence; 2 | 3 | import java.io.Serializable; 4 | 5 | import com.tengjie.common.utils.StringUtils; 6 | 7 | public class DataEntityFieldCallBackBean implements Serializable { 8 | private static final long serialVersionUID = 1L; 9 | private String className;//必须带包名 10 | private String methodName;//方法 名,对于导入 11 | private Object[] otherParam;//其他传入的参数 12 | private boolean quick=false;//新增属性,供快速回调使用 13 | private boolean ifToolMethod=false;//是否调用的是如dateUtils等工具类,如果是的话,则只返回值,不包含resultset 14 | private String tableName;//新增属性,供快速回调使用 15 | private String resultPropName;//新增属性,供快速回调使用 16 | private String queryPropName;// 要查询的属性名,供快速回调使用 17 | private String valuePropName;// 要查询的属性名,值属性名称,可以是当前查询中任何一个其他查询字段的值 18 | 19 | public DataEntityFieldCallBackBean() { 20 | super(); 21 | } 22 | public DataEntityFieldCallBackBean(boolean quick, String tableName, 23 | String resultPropName,String queryPropName,String valuePropName) { 24 | super(); 25 | this.quick = quick; 26 | this.tableName = tableName; 27 | this.resultPropName = resultPropName; 28 | this.queryPropName = queryPropName; 29 | this.valuePropName = valuePropName; 30 | } 31 | public DataEntityFieldCallBackBean( 32 | String className, String methodName) { 33 | super(); 34 | 35 | this.className = className; 36 | this.methodName = methodName; 37 | } 38 | /** 39 | * 40 | * @param className:若在spring环境中的类,则可以直接用小写开头的类名,否则的话要用全路径 41 | * @param methodName 42 | * @param otherParam 43 | */ 44 | public DataEntityFieldCallBackBean( 45 | String className, String methodName,Object[] otherParam) { 46 | super(); 47 | 48 | this.className = className; 49 | this.methodName = methodName; 50 | this.otherParam=otherParam; 51 | } 52 | public DataEntityFieldCallBackBean( 53 | Object currObj, String methodName,Object[] otherParam) { 54 | super(); 55 | 56 | this.className = StringUtils.firstToLower(currObj.getClass().getSimpleName()); 57 | this.methodName = methodName; 58 | this.otherParam=otherParam; 59 | } 60 | 61 | public String getClassName() { 62 | return className; 63 | } 64 | public void setClassName(String className) { 65 | this.className = className; 66 | } 67 | public String getMethodName() { 68 | return methodName; 69 | } 70 | public void setMethodName(String methodName) { 71 | this.methodName = methodName; 72 | } 73 | 74 | public Object[] getOtherParam() { 75 | return otherParam; 76 | } 77 | 78 | public void setOtherParam(Object[] otherParam) { 79 | this.otherParam = otherParam; 80 | } 81 | public boolean isQuick() { 82 | return quick; 83 | } 84 | public void setQuick(boolean quick) { 85 | this.quick = quick; 86 | } 87 | public String getTableName() { 88 | return tableName; 89 | } 90 | public void setTableName(String tableName) { 91 | this.tableName = tableName; 92 | } 93 | public String getResultPropName() { 94 | return resultPropName; 95 | } 96 | public void setResultPropName(String resultPropName) { 97 | this.resultPropName = resultPropName; 98 | } 99 | public String getQueryPropName() { 100 | return queryPropName; 101 | } 102 | public void setQueryPropName(String queryPropName) { 103 | this.queryPropName = queryPropName; 104 | } 105 | public String getValuePropName() { 106 | return valuePropName; 107 | } 108 | public void setValuePropName(String valuePropName) { 109 | this.valuePropName = valuePropName; 110 | } 111 | public boolean isIfToolMethod() { 112 | return ifToolMethod; 113 | } 114 | public void setIfToolMethod(boolean ifToolMethod) { 115 | this.ifToolMethod = ifToolMethod; 116 | } 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/DynaPropertyBeanForRpc.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence; 2 | 3 | import java.io.Serializable; 4 | /** 5 | * 在rpc时,保存动态属性的类型和值 6 | * @author liangfeng 7 | * 8 | */ 9 | public class DynaPropertyBeanForRpc implements Serializable { 10 | private String fieldName; 11 | private Class fieldClassType; 12 | private Object fieldValue; 13 | public String getFieldName() { 14 | return fieldName; 15 | } 16 | public void setFieldName(String fieldName) { 17 | this.fieldName = fieldName; 18 | } 19 | public Class getFieldClassType() { 20 | return fieldClassType; 21 | } 22 | public void setFieldClassType(Class fieldClassType) { 23 | this.fieldClassType = fieldClassType; 24 | } 25 | public Object getFieldValue() { 26 | return fieldValue; 27 | } 28 | public void setFieldValue(Object fieldValue) { 29 | this.fieldValue = fieldValue; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/PageMap.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence; 2 | import java.io.Serializable; 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.tengjie.common.config.Global; 7 | /** 8 | * Created by hzl on 2017/7/11. 9 | */ 10 | public class PageMap implements Serializable { 11 | 12 | protected Integer pageNo = 1; // 当前页码 13 | protected Integer pageSize = Integer.valueOf(Global.getConfig("page.pageSize")); // 页面大小,设置为“-1”表示不进行分页(分页无效) 14 | 15 | protected long count;// 总记录数,设置为“-1”表示不查询总数 16 | 17 | protected Integer totalPage; //总页码 18 | private List list = new ArrayList(); 19 | private boolean ifCount=true;//是否查询分业count数据,如果查询会执行select count(1) from sql 20 | 21 | public int getPageNo() { 22 | return pageNo; 23 | } 24 | 25 | public void setPageNo(Integer pageNo) { 26 | if(pageNo == null)return; 27 | if(pageNo > 0){ 28 | this.pageNo = pageNo; 29 | } 30 | } 31 | 32 | public int getPageSize() { 33 | return pageSize; 34 | } 35 | 36 | public void setPageSize(Integer pageSize) { 37 | if (pageSize == null)return; 38 | if(pageSize > 0){ 39 | this.pageSize = pageSize; 40 | } 41 | if(pageSize < 0){ 42 | this.pageSize = pageSize; 43 | } 44 | } 45 | 46 | public long getCount() { 47 | return count; 48 | } 49 | 50 | public void setCount(long count) { 51 | this.count = count; 52 | } 53 | 54 | public List getList() { 55 | return list; 56 | } 57 | 58 | public void setList(List list) { 59 | this.list = list; 60 | } 61 | 62 | /** 63 | * 获取 Hibernate FirstResult 64 | */ 65 | public int getFirstResult(){ 66 | int firstResult = (getPageNo() - 1) * getPageSize(); 67 | /*if (firstResult >= getCount() || firstResult<0) { 68 | firstResult = 0; 69 | }*/ 70 | return firstResult; 71 | } 72 | /** 73 | * 获取 Hibernate MaxResults 74 | */ 75 | public int getMaxResults(){ 76 | return getPageSize(); 77 | } 78 | 79 | public int getTotalPage() { 80 | return totalPage; 81 | } 82 | 83 | public void setTotalPage(Integer totalPage) { 84 | this.totalPage = totalPage; 85 | } 86 | 87 | public void init(){ 88 | int count = (int)this.getCount(); 89 | int pageSize = this.getPageSize(); 90 | int total = count%pageSize == 0 ? count/pageSize : (count/pageSize)+1; 91 | this.setTotalPage(total); 92 | } 93 | 94 | public PageMap(Integer pageNo, Integer pageSize) { 95 | if (pageNo == null) { 96 | return; 97 | } 98 | if (pageNo > 0) { 99 | this.pageNo = pageNo; 100 | } 101 | if (pageSize == null) { 102 | return; 103 | } 104 | if (pageSize > 0) { 105 | this.pageSize = pageSize; 106 | } 107 | } 108 | 109 | public boolean getIfCount() { 110 | return ifCount; 111 | } 112 | 113 | public void setIfCount(boolean ifCount) { 114 | this.ifCount = ifCount; 115 | } 116 | 117 | public PageMap() {} 118 | } 119 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/Parameter.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence; 2 | 3 | import java.util.HashMap; 4 | 5 | /** 6 | * 查询参数类 7 | * @author 8 | * @version 2013-8-23 9 | */ 10 | public class Parameter extends HashMap { 11 | 12 | private static final long serialVersionUID = 1L; 13 | 14 | /** 15 | * 构造类,例:new Parameter(id, parentIds) 16 | * @param values 参数值 17 | */ 18 | public Parameter(Object... values) { 19 | if (values != null){ 20 | for (int i=0; i 0 && !hasDistinct(sql)) { 26 | rownumber.append(sql.substring(orderByIndex)); 27 | } 28 | 29 | rownumber.append(") as rownumber_,"); 30 | 31 | return rownumber.toString(); 32 | } 33 | 34 | private static boolean hasDistinct(String sql) { 35 | return sql.toLowerCase().contains("select distinct"); 36 | } 37 | 38 | @Override 39 | public String getLimitString(String sql, int offset, int limit) { 40 | return getLimitString(sql, offset, Integer.toString(offset), Integer.toString(limit)); 41 | } 42 | 43 | /** 44 | * 将sql变成分页sql语句,提供将offset及limit使用占位符号(placeholder)替换. 45 | *

46 |      * 如mysql
47 |      * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
48 |      * select * from user limit :offset,:limit
49 |      * 
50 | * 51 | * @param sql 实际SQL语句 52 | * @param offset 分页开始纪录条数 53 | * @param offsetPlaceholder 分页开始纪录条数-占位符号 54 | * @param limitPlaceholder 分页纪录条数占位符号 55 | * @return 包含占位符的分页sql 56 | */ 57 | public String getLimitString(String sql, int offset, String offsetPlaceholder, String limitPlaceholder) { 58 | int startOfSelect = sql.toLowerCase().indexOf("select"); 59 | 60 | StringBuilder pagingSelect = new StringBuilder(sql.length() + 100) 61 | .append(sql.substring(0, startOfSelect)) //add the comment 62 | .append("select * from ( select ") //nest the main query in an outer select 63 | .append(getRowNumber(sql)); //add the rownnumber bit into the outer query select list 64 | 65 | if (hasDistinct(sql)) { 66 | pagingSelect.append(" row_.* from ( ") //add another (inner) nested select 67 | .append(sql.substring(startOfSelect)) //add the main query 68 | .append(" ) as row_"); //close off the inner nested select 69 | } else { 70 | pagingSelect.append(sql.substring(startOfSelect + 6)); //add the main query 71 | } 72 | 73 | pagingSelect.append(" ) as temp_ where rownumber_ "); 74 | 75 | //add the restriction to the outer select 76 | if (offset > 0) { 77 | // int end = offset + limit; 78 | String endString = offsetPlaceholder + "+" + limitPlaceholder; 79 | pagingSelect.append("between ").append(offsetPlaceholder) 80 | .append("+1 and ").append(endString); 81 | } else { 82 | pagingSelect.append("<= ").append(limitPlaceholder); 83 | } 84 | 85 | return pagingSelect.toString(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/dialect/db/DerbyDialect.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence.dialect.db; 2 | 3 | import com.tengjie.common.persistence.dialect.Dialect; 4 | 5 | /** 6 | * @author 7 | * @version 1.0 2010-10-10 下午12:31 8 | * @since JDK 1.5 9 | */ 10 | public class DerbyDialect implements Dialect { 11 | @Override 12 | public boolean supportsLimit() { 13 | return false; 14 | } 15 | 16 | @Override 17 | public String getLimitString(String sql, int offset, int limit) { 18 | // return getLimitString(sql,offset,Integer.toString(offset),limit,Integer.toString(limit)); 19 | throw new UnsupportedOperationException("paged queries not supported"); 20 | } 21 | 22 | /** 23 | * 将sql变成分页sql语句,提供将offset及limit使用占位符号(placeholder)替换. 24 | *
25 |      * 如mysql
26 |      * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
27 |      * select * from user limit :offset,:limit
28 |      * 
29 | * 30 | * @param sql 实际SQL语句 31 | * @param offset 分页开始纪录条数 32 | * @param offsetPlaceholder 分页开始纪录条数-占位符号 33 | * @param limit 分页每页显示纪录条数 34 | * @param limitPlaceholder 分页纪录条数占位符号 35 | * @return 包含占位符的分页sql 36 | */ 37 | public String getLimitString(String sql, int offset,String offsetPlaceholder, int limit, String limitPlaceholder) { 38 | throw new UnsupportedOperationException( "paged queries not supported" ); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/dialect/db/H2Dialect.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence.dialect.db; 2 | 3 | import com.tengjie.common.persistence.dialect.Dialect; 4 | 5 | 6 | /** 7 | * A dialect compatible with the H2 database. 8 | * 9 | * @author 10 | * @version 1.0 2010-10-10 下午12:31 11 | * @since JDK 1.5 12 | */ 13 | public class H2Dialect implements Dialect { 14 | 15 | public boolean supportsLimit() { 16 | return true; 17 | } 18 | 19 | /** 20 | * 将sql变成分页sql语句,提供将offset及limit使用占位符号(placeholder)替换. 21 | *
22 |      * 如mysql
23 |      * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
24 |      * select * from user limit :offset,:limit
25 |      * 
26 | * 27 | * @param sql 实际SQL语句 28 | * @param offset 分页开始纪录条数 29 | * @param offsetPlaceholder 分页开始纪录条数-占位符号 30 | * @param limit 分页每页显示纪录条数 31 | * @param limitPlaceholder 分页纪录条数占位符号 32 | * @return 包含占位符的分页sql 33 | */ 34 | private String getLimitString(String sql, int offset, String offsetPlaceholder, int limit, String limitPlaceholder) { 35 | return sql + ((offset > 0) ? " limit " + limitPlaceholder + " offset " 36 | + offsetPlaceholder : " limit " + limitPlaceholder); 37 | } 38 | 39 | @Override 40 | public String getLimitString(String sql, int offset, int limit) { 41 | return getLimitString(sql, offset, Integer.toString(offset), limit, Integer.toString(limit)); 42 | } 43 | } -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/dialect/db/HSQLDialect.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence.dialect.db; 2 | 3 | import com.tengjie.common.persistence.dialect.Dialect; 4 | 5 | 6 | /** 7 | * Dialect for HSQLDB 8 | * 9 | * @author 10 | * @version 1.0 2010-10-10 下午12:31 11 | * @since JDK 1.5 12 | */ 13 | public class HSQLDialect implements Dialect { 14 | @Override 15 | public boolean supportsLimit() { 16 | return true; 17 | } 18 | 19 | @Override 20 | public String getLimitString(String sql, int offset, int limit) { 21 | return getLimitString(sql, offset, Integer.toString(offset), 22 | Integer.toString(limit)); 23 | } 24 | 25 | /** 26 | * 将sql变成分页sql语句,提供将offset及limit使用占位符号(placeholder)替换. 27 | *
28 |      * 如mysql
29 |      * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
30 |      * select * from user limit :offset,:limit
31 |      * 
32 | * 33 | * @param sql 实际SQL语句 34 | * @param offset 分页开始纪录条数 35 | * @param offsetPlaceholder 分页开始纪录条数-占位符号 36 | * @param limitPlaceholder 分页纪录条数占位符号 37 | * @return 包含占位符的分页sql 38 | */ 39 | public String getLimitString(String sql, int offset, String offsetPlaceholder, String limitPlaceholder) { 40 | boolean hasOffset = offset > 0; 41 | return 42 | new StringBuffer(sql.length() + 10) 43 | .append(sql) 44 | .insert(sql.toLowerCase().indexOf("select") + 6, hasOffset ? " limit " + offsetPlaceholder + " " + limitPlaceholder : " top " + limitPlaceholder) 45 | .toString(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/dialect/db/MySQLDialect.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence.dialect.db; 2 | 3 | import com.tengjie.common.persistence.dialect.Dialect; 4 | 5 | /** 6 | * Mysql方言的实现 7 | * 8 | * @author 9 | * @version 1.0 2010-10-10 下午12:31 10 | * @since JDK 1.5 11 | */ 12 | public class MySQLDialect implements Dialect { 13 | 14 | 15 | @Override 16 | public String getLimitString(String sql, int offset, int limit) { 17 | return getLimitString(sql, offset, Integer.toString(offset), 18 | Integer.toString(limit)); 19 | } 20 | 21 | public boolean supportsLimit() { 22 | return true; 23 | } 24 | 25 | /** 26 | * 将sql变成分页sql语句,提供将offset及limit使用占位符号(placeholder)替换. 27 | *
28 |      * 如mysql
29 |      * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
30 |      * select * from user limit :offset,:limit
31 |      * 
32 | * 33 | * @param sql 实际SQL语句 34 | * @param offset 分页开始纪录条数 35 | * @param offsetPlaceholder 分页开始纪录条数-占位符号 36 | * @param limitPlaceholder 分页纪录条数占位符号 37 | * @return 包含占位符的分页sql 38 | */ 39 | public String getLimitString(String sql, int offset, String offsetPlaceholder, String limitPlaceholder) { 40 | StringBuilder stringBuilder = new StringBuilder(sql); 41 | stringBuilder.append(" limit "); 42 | if (offset > 0) { 43 | stringBuilder.append(offsetPlaceholder).append(",").append(limitPlaceholder); 44 | } else { 45 | stringBuilder.append(limitPlaceholder); 46 | } 47 | return stringBuilder.toString(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/dialect/db/OracleDialect.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence.dialect.db; 2 | 3 | import com.tengjie.common.persistence.dialect.Dialect; 4 | /** 5 | * Oracle的方言实现 6 | * @author 7 | * @version 1.0 2010-10-10 下午12:31 8 | * @since JDK 1.5 9 | */ 10 | public class OracleDialect implements Dialect { 11 | @Override 12 | public boolean supportsLimit() { 13 | return true; 14 | } 15 | 16 | @Override 17 | public String getLimitString(String sql, int offset, int limit) { 18 | return getLimitString(sql, offset, Integer.toString(offset), Integer.toString(limit)); 19 | } 20 | 21 | /** 22 | * 将sql变成分页sql语句,提供将offset及limit使用占位符号(placeholder)替换. 23 | *
24 |      * 如mysql
25 |      * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
26 |      * select * from user limit :offset,:limit
27 |      * 
28 | * 29 | * @param sql 实际SQL语句 30 | * @param offset 分页开始纪录条数 31 | * @param offsetPlaceholder 分页开始纪录条数-占位符号 32 | * @param limitPlaceholder 分页纪录条数占位符号 33 | * @return 包含占位符的分页sql 34 | */ 35 | public String getLimitString(String sql, int offset, String offsetPlaceholder, String limitPlaceholder) { 36 | sql = sql.trim(); 37 | boolean isForUpdate = false; 38 | if (sql.toLowerCase().endsWith(" for update")) { 39 | sql = sql.substring(0, sql.length() - 11); 40 | isForUpdate = true; 41 | } 42 | StringBuilder pagingSelect = new StringBuilder(sql.length() + 100); 43 | 44 | if (offset > 0) { 45 | pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( "); 46 | } else { 47 | pagingSelect.append("select * from ( "); 48 | } 49 | pagingSelect.append(sql); 50 | if (offset > 0) { 51 | String endString = offsetPlaceholder + "+" + limitPlaceholder; 52 | pagingSelect.append(" ) row_ where rownum <= "+endString+") where rownum_ > ").append(offsetPlaceholder); 53 | } else { 54 | pagingSelect.append(" ) where rownum <= "+limitPlaceholder); 55 | } 56 | 57 | if (isForUpdate) { 58 | pagingSelect.append(" for update"); 59 | } 60 | 61 | return pagingSelect.toString(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/dialect/db/PostgreSQLDialect.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence.dialect.db; 2 | 3 | import com.tengjie.common.persistence.dialect.Dialect; 4 | /** 5 | * Postgre Sql的方言实现 6 | * @author 7 | * @version 1.0 2010-10-10 下午12:31 8 | * @since JDK 1.5 9 | */ 10 | public class PostgreSQLDialect implements Dialect { 11 | 12 | public boolean supportsLimit() { 13 | return true; 14 | } 15 | 16 | @Override 17 | public String getLimitString(String sql, int offset, int limit) { 18 | return getLimitString(sql, offset, Integer.toString(offset), 19 | Integer.toString(limit)); 20 | } 21 | 22 | /** 23 | * 将sql变成分页sql语句,提供将offset及limit使用占位符号(placeholder)替换. 24 | *
25 |      * 如mysql
26 |      * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
27 |      * select * from user limit :offset,:limit
28 |      * 
29 | * 30 | * @param sql 实际SQL语句 31 | * @param offset 分页开始纪录条数 32 | * @param offsetPlaceholder 分页开始纪录条数-占位符号 33 | * @param limitPlaceholder 分页纪录条数占位符号 34 | * @return 包含占位符的分页sql 35 | */ 36 | public String getLimitString(String sql, int offset, 37 | String offsetPlaceholder, String limitPlaceholder) { 38 | StringBuilder pageSql = new StringBuilder().append(sql); 39 | pageSql = offset <= 0 40 | ? pageSql.append(" limit ").append(limitPlaceholder) : 41 | pageSql.append(" limit ").append(limitPlaceholder).append(" offset ").append(offsetPlaceholder); 42 | return pageSql.toString(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/dialect/db/SQLServer2005Dialect.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence.dialect.db; 2 | import com.tengjie.common.persistence.dialect.Dialect; 3 | import com.tengjie.common.utils.StringUtils; 4 | /** 5 | * Sql 2005的方言实现 6 | * @author 7 | * @version 1.0 2010-10-10 下午12:31 8 | * @since JDK 1.5 9 | */ 10 | public class SQLServer2005Dialect implements Dialect { 11 | 12 | @Override 13 | public boolean supportsLimit() { 14 | return true; 15 | } 16 | 17 | @Override 18 | public String getLimitString(String sql, int offset, int limit) { 19 | return getLimitString(sql, offset, 20 | limit, Integer.toString(limit)); 21 | } 22 | 23 | /** 24 | * Add a LIMIT clause to the given SQL SELECT 25 | *

26 | * The LIMIT SQL will look like: 27 | *

28 | * WITH query AS 29 | * (SELECT TOP 100 percent ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __row_number__, * from table_name) 30 | * SELECT * 31 | * FROM query 32 | * WHERE __row_number__ BETWEEN :offset and :lastRows 33 | * ORDER BY __row_number__ 34 | * 35 | * @param querySqlString The SQL statement to base the limit query off of. 36 | * @param offset Offset of the first row to be returned by the query (zero-based) 37 | * @param limit Maximum number of rows to be returned by the query 38 | * @param limitPlaceholder limitPlaceholder 39 | * @return A new SQL statement with the LIMIT clause applied. 40 | */ 41 | private String getLimitString(String querySqlString, int offset, int limit, String limitPlaceholder) { 42 | StringBuilder pagingBuilder = new StringBuilder(); 43 | String orderby = getOrderByPart(querySqlString); 44 | String distinctStr = ""; 45 | 46 | String loweredString = querySqlString.toLowerCase(); 47 | String sqlPartString = querySqlString; 48 | if (loweredString.trim().startsWith("select")) { 49 | int index = 6; 50 | if (loweredString.startsWith("select distinct")) { 51 | distinctStr = "DISTINCT "; 52 | index = 15; 53 | } 54 | sqlPartString = sqlPartString.substring(index); 55 | } 56 | pagingBuilder.append(sqlPartString); 57 | 58 | // if no ORDER BY is specified use fake ORDER BY field to avoid errors 59 | if (StringUtils.isEmpty(orderby)) { 60 | orderby = "ORDER BY CURRENT_TIMESTAMP"; 61 | } 62 | 63 | StringBuilder result = new StringBuilder(); 64 | result.append("WITH query AS (SELECT ") 65 | .append(distinctStr) 66 | .append("TOP 100 PERCENT ") 67 | .append(" ROW_NUMBER() OVER (") 68 | .append(orderby) 69 | .append(") as __row_number__, ") 70 | .append(pagingBuilder) 71 | .append(") SELECT * FROM query WHERE __row_number__ BETWEEN ") 72 | .append(offset).append(" AND ").append(offset + limit) 73 | .append(" ORDER BY __row_number__"); 74 | 75 | return result.toString(); 76 | } 77 | 78 | static String getOrderByPart(String sql) { 79 | String loweredString = sql.toLowerCase(); 80 | int orderByIndex = loweredString.indexOf("order by"); 81 | if (orderByIndex != -1) { 82 | // if we find a new "order by" then we need to ignore 83 | // the previous one since it was probably used for a subquery 84 | return sql.substring(orderByIndex); 85 | } else { 86 | return ""; 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/dialect/db/SQLServerDialect.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence.dialect.db; 2 | import com.tengjie.common.persistence.dialect.Dialect; 3 | /** 4 | * MSSQLServer 数据库实现分页方言 5 | * 6 | * @author 7 | * @version 1.0 2010-10-10 下午12:31 8 | * @since JDK 1.5 9 | */ 10 | public class SQLServerDialect implements Dialect { 11 | 12 | public boolean supportsLimit() { 13 | return true; 14 | } 15 | 16 | static int getAfterSelectInsertPoint(String sql) { 17 | int selectIndex = sql.toLowerCase().indexOf("select"); 18 | final int selectDistinctIndex = sql.toLowerCase().indexOf("select distinct"); 19 | return selectIndex + (selectDistinctIndex == selectIndex ? 15 : 6); 20 | } 21 | 22 | public String getLimitString(String sql, int offset, int limit) { 23 | return getLimit(sql, offset, limit); 24 | } 25 | 26 | /** 27 | * 将sql变成分页sql语句,提供将offset及limit使用占位符号(placeholder)替换. 28 | *

29 |      * 如mysql
30 |      * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
31 |      * select * from user limit :offset,:limit
32 |      * 
33 | * 34 | * @param sql 实际SQL语句 35 | * @param offset 分页开始纪录条数 36 | * @param limit 分页每页显示纪录条数 37 | * @return 包含占位符的分页sql 38 | */ 39 | public String getLimit(String sql, int offset, int limit) { 40 | if (offset > 0) { 41 | throw new UnsupportedOperationException("sql server has no offset"); 42 | } 43 | return new StringBuffer(sql.length() + 8) 44 | .append(sql) 45 | .insert(getAfterSelectInsertPoint(sql), " top " + limit) 46 | .toString(); 47 | } 48 | 49 | 50 | } 51 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/dialect/db/SybaseDialect.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence.dialect.db; 2 | 3 | import com.tengjie.common.persistence.dialect.Dialect; 4 | /** 5 | * Sybase数据库分页方言实现。 6 | * 还未实现 7 | * 8 | * @author 9 | * @version 1.0 2010-10-10 下午12:31 10 | * @since JDK 1.5 11 | */ 12 | public class SybaseDialect implements Dialect { 13 | 14 | public boolean supportsLimit() { 15 | return false; 16 | } 17 | 18 | 19 | @Override 20 | public String getLimitString(String sql, int offset, int limit) { 21 | return null; 22 | } 23 | 24 | /** 25 | * 将sql变成分页sql语句,提供将offset及limit使用占位符号(placeholder)替换. 26 | *
27 |      * 如mysql
28 |      * dialect.getLimitString("select * from user", 12, ":offset",0,":limit") 将返回
29 |      * select * from user limit :offset,:limit
30 |      * 
31 | * 32 | * @param sql 实际SQL语句 33 | * @param offset 分页开始纪录条数 34 | * @param offsetPlaceholder 分页开始纪录条数-占位符号 35 | * @param limit 分页每页显示纪录条数 36 | * @param limitPlaceholder 分页纪录条数占位符号 37 | * @return 包含占位符的分页sql 38 | */ 39 | public String getLimitString(String sql, int offset, String offsetPlaceholder, int limit, String limitPlaceholder) { 40 | throw new UnsupportedOperationException("paged queries not supported"); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /tengjie-base/src/main/java/com/tengjie/common/persistence/interceptor/PreparePaginationInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.tengjie.common.persistence.interceptor; 2 | 3 | import java.sql.Connection; 4 | import java.util.Properties; 5 | 6 | import org.apache.ibatis.executor.statement.BaseStatementHandler; 7 | import org.apache.ibatis.executor.statement.RoutingStatementHandler; 8 | import org.apache.ibatis.executor.statement.StatementHandler; 9 | import org.apache.ibatis.mapping.BoundSql; 10 | import org.apache.ibatis.mapping.MappedStatement; 11 | import org.apache.ibatis.plugin.Intercepts; 12 | import org.apache.ibatis.plugin.Invocation; 13 | import org.apache.ibatis.plugin.Plugin; 14 | import org.apache.ibatis.plugin.Signature; 15 | 16 | import com.tengjie.common.persistence.Page; 17 | import com.tengjie.common.utils.Reflections; 18 | 19 | 20 | /** 21 | * Mybatis数据库分页插件,拦截StatementHandler的prepare方法 22 | * @author 23 | * @version 2013-8-28 24 | */ 25 | @Intercepts({ 26 | @Signature(type = StatementHandler.class, method = "prepare", args = {Connection.class}) 27 | }) 28 | public class PreparePaginationInterceptor extends BaseInterceptor { 29 | 30 | private static final long serialVersionUID = 1L; 31 | 32 | public PreparePaginationInterceptor() { 33 | super(); 34 | } 35 | 36 | @Override 37 | public Object intercept(Invocation ivk) throws Throwable { 38 | if (ivk.getTarget().getClass().isAssignableFrom(RoutingStatementHandler.class)) { 39 | final RoutingStatementHandler statementHandler = (RoutingStatementHandler) ivk.getTarget(); 40 | final BaseStatementHandler delegate = (BaseStatementHandler) Reflections.getFieldValue(statementHandler, DELEGATE); 41 | final MappedStatement mappedStatement = (MappedStatement) Reflections.getFieldValue(delegate, MAPPED_STATEMENT); 42 | 43 | // //拦截需要分页的SQL 44 | //// if (mappedStatement.getId().matches(_SQL_PATTERN)) { 45 | // if (StringUtils.indexOfIgnoreCase(mappedStatement.getId(), _SQL_PATTERN) != -1) { 46 | BoundSql boundSql = delegate.getBoundSql(); 47 | //分页SQL