=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 extends ConstraintViolation> 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 extends ConstraintViolation> 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 extends ConstraintViolation> 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 extends ConstraintViolation> 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中parameterType属性对应的实体参数,即Mapper接口中执行分页方法的参数,该参数不得为空
48 | Object parameterObject = boundSql.getParameterObject();
49 | if (parameterObject == null) {
50 | log.error("参数未实例化");
51 | throw new NullPointerException("parameterObject尚未实例化!");
52 | } else {
53 | final Connection connection = (Connection) ivk.getArgs()[0];
54 | final String sql = boundSql.getSql();
55 | //记录统计
56 | final int count = SQLHelper.getCount(sql, connection, mappedStatement, parameterObject, boundSql, log);
57 | Page page = null;
58 | page = convertParameter(parameterObject, page);
59 | page.setCount(count);
60 | String pagingSql = SQLHelper.generatePageSql(sql, page, DIALECT);
61 | if (log.isDebugEnabled()) {
62 | log.debug("PAGE SQL:" + pagingSql);
63 | }
64 | //将分页sql语句反射回BoundSql.
65 | Reflections.setFieldValue(boundSql, "sql", pagingSql);
66 | }
67 |
68 | if (boundSql.getSql() == null || "".equals(boundSql.getSql())){
69 | return null;
70 | }
71 |
72 | }
73 | // }
74 | return ivk.proceed();
75 | }
76 |
77 |
78 | @Override
79 | public Object plugin(Object o) {
80 | return Plugin.wrap(o, this);
81 | }
82 |
83 | @Override
84 | public void setProperties(Properties properties) {
85 | initProperties(properties);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/persistence/proxy/PageConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.persistence.proxy;
2 |
3 | import org.apache.ibatis.binding.MapperRegistry;
4 | import org.apache.ibatis.session.Configuration;
5 | import org.apache.ibatis.session.SqlSession;
6 |
7 | /**
8 | *
9 | * 自定义Mybatis的配置,扩展.
10 | *
11 | *
12 | * @author
13 | * @version 1.0 2012-05-13 上午10:06
14 | * @since JDK 1.5
15 | */
16 | public class PageConfiguration extends Configuration {
17 |
18 | protected MapperRegistry mapperRegistry = new PaginationMapperRegistry(this);
19 |
20 | @Override
21 | public void addMapper(Class type) {
22 | mapperRegistry.addMapper(type);
23 | }
24 |
25 | @Override
26 | public T getMapper(Class type, SqlSession sqlSession) {
27 | return mapperRegistry.getMapper(type, sqlSession);
28 | }
29 |
30 | @Override
31 | public boolean hasMapper(Class> type) {
32 | return mapperRegistry.hasMapper(type);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/persistence/proxy/PaginationMapperProxy.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.persistence.proxy;
2 |
3 | import java.lang.reflect.InvocationHandler;
4 | import java.lang.reflect.Method;
5 | import java.lang.reflect.Proxy;
6 | import java.util.HashSet;
7 | import java.util.Set;
8 |
9 | import org.apache.ibatis.binding.BindingException;
10 | import org.apache.ibatis.binding.MapperMethod;
11 | import org.apache.ibatis.session.SqlSession;
12 |
13 | import com.tengjie.common.persistence.Page;
14 | import com.tengjie.common.utils.Reflections;
15 |
16 | /**
17 | *
18 | * .
19 | *
20 | *
21 | * @author
22 | * @version 1.0 2012-05-13 上午10:07
23 | * @since JDK 1.5
24 | */
25 | public class PaginationMapperProxy implements InvocationHandler {
26 |
27 |
28 | private static final Set OBJECT_METHODS = new HashSet() {
29 | private static final long serialVersionUID = -1782950882770203583L;
30 | {
31 | add("toString");
32 | add("getClass");
33 | add("hashCode");
34 | add("equals");
35 | add("wait");
36 | add("notify");
37 | add("notifyAll");
38 | }
39 | };
40 |
41 | private boolean isObjectMethod(Method method) {
42 | return OBJECT_METHODS.contains(method.getName());
43 | }
44 |
45 | private final SqlSession sqlSession;
46 |
47 | private PaginationMapperProxy(final SqlSession sqlSession) {
48 | this.sqlSession = sqlSession;
49 | }
50 |
51 | @Override
52 | public Object invoke(Object proxy, Method method, Object[] args)
53 | throws Throwable {
54 | if (isObjectMethod(method)) {
55 | return null;
56 | }
57 | final Class> declaringInterface = findDeclaringInterface(proxy, method);
58 | if (Page.class.isAssignableFrom(method.getReturnType())) {
59 | // 分页处理
60 | return new PaginationMapperMethod(declaringInterface, method, sqlSession).execute(args);
61 | }
62 | // 原处理方式
63 | final MapperMethod mapperMethod = new MapperMethod(declaringInterface, method, sqlSession.getConfiguration());
64 | final Object result = mapperMethod.execute(sqlSession, args);
65 | if (result == null && method.getReturnType().isPrimitive()) {
66 | throw new BindingException(
67 | "Mapper method '"
68 | + method.getName()
69 | + "' ("
70 | + method.getDeclaringClass()
71 | + ") attempted to return null from a method with a primitive return type ("
72 | + method.getReturnType() + ").");
73 | }
74 | return result;
75 | }
76 |
77 | private Class> findDeclaringInterface(Object proxy, Method method) {
78 | Class> declaringInterface = null;
79 | for (Class> mapperFaces : proxy.getClass().getInterfaces()) {
80 | Method m = Reflections.getAccessibleMethod(mapperFaces,
81 | method.getName(),
82 | method.getParameterTypes());
83 | if (m != null) {
84 | declaringInterface = mapperFaces;
85 | }
86 | }
87 | if (declaringInterface == null) {
88 | throw new BindingException(
89 | "Could not find interface with the given method " + method);
90 | }
91 | return declaringInterface;
92 | }
93 |
94 | @SuppressWarnings("unchecked")
95 | public static T newMapperProxy(Class mapperInterface, SqlSession sqlSession) {
96 | ClassLoader classLoader = mapperInterface.getClassLoader();
97 | Class>[] interfaces = new Class[]{mapperInterface};
98 | PaginationMapperProxy proxy = new PaginationMapperProxy(sqlSession);
99 | return (T) Proxy.newProxyInstance(classLoader, interfaces, proxy);
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/persistence/proxy/PaginationMapperRegistry.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.persistence.proxy;
2 |
3 | import org.apache.ibatis.binding.BindingException;
4 | import org.apache.ibatis.binding.MapperRegistry;
5 | import org.apache.ibatis.session.Configuration;
6 | import org.apache.ibatis.session.SqlSession;
7 |
8 | /**
9 | *
10 | * .
11 | *
12 | *
13 | * @author
14 | * @version 1.0 2012-05-13 上午10:06
15 | * @since JDK 1.5
16 | */
17 | public class PaginationMapperRegistry extends MapperRegistry {
18 | public PaginationMapperRegistry(Configuration config) {
19 | super(config);
20 | }
21 |
22 | @Override
23 | public T getMapper(Class type, SqlSession sqlSession) {
24 | if (!hasMapper(type)) {
25 | throw new BindingException("Type " + type + " is not known to the MapperRegistry.");
26 | }
27 | try {
28 | return PaginationMapperProxy.newMapperProxy(type, sqlSession);
29 | } catch (Exception e) {
30 | throw new BindingException("Error getting mapper instance. Cause: " + e, e);
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/persistence/util/CollectFunctionConstantTool.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.persistence.util;
2 | /**
3 | * 聚合函数常量
4 | * @author liangfeng
5 | *
6 | */
7 | public class CollectFunctionConstantTool {
8 | public static String COUNT = "count";
9 | public static String MAX = "max";
10 | public static String MIN= "min";
11 | public static String SUM = "sum";
12 | public static String AVG = "avg";
13 | public static String LEAST = "least";
14 | }
15 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/persistence/util/DbTablePrimaryKeyFieldConfig.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.persistence.util;
2 |
3 | import java.sql.Connection;
4 | import java.sql.PreparedStatement;
5 | import java.sql.ResultSet;
6 | import java.util.Map;
7 |
8 | import javax.servlet.ServletContext;
9 |
10 | import org.springframework.stereotype.Component;
11 | import org.springframework.web.context.ServletContextAware;
12 |
13 | import com.google.common.collect.Maps;
14 | import com.tengjie.common.config.Global;
15 | import com.tengjie.common.persistence.TjBaseEntity;
16 | import com.tengjie.common.utils.PackageUtil;
17 | import com.tengjie.common.utils.SpringContextHolder;
18 | import com.tengjie.common.utils.StringUtils;
19 | import com.tengjie.common.utils.TjNewMap;
20 |
21 | /**
22 | * 由于在程序中很多地方,比如说查询表的下拉框,关键值会直接用id字段,但是有些表比如city、province她的主键不是id,
23 | * 并且有些程序其他的地方也是这个原则,或者给其他人用这个封装,他们的表的主键不一定叫id,
24 | * 因此这里会全局配置表的id字段配置,在本类中只针对我们自己的项目中的某几张表,并且预置好了,
25 | * 然后在配置文件中会有dbTablePrimaryKeyFieldConfig="自定义类路径";,会优先加载这个
26 | * 自定义类路径,这个类也要定义一个方法public static void buildKeyFieldsMap()来覆盖这个父类方法。
27 | *
28 | * @author admin
29 | *
30 | */
31 | @Component
32 | public class DbTablePrimaryKeyFieldConfig implements ServletContextAware{
33 | private static final String idFieldName="id";
34 | private static String schemaName=Global.getConfig("jdbc.schemaName");
35 | public static Connection conn=null;
36 | protected static TjNewMap keyFieldsMap=TjNewMap.newInstance();//key为数据库表名,value为主键字段名,字段名是驼峰后的
37 | @Override
38 | public void setServletContext(ServletContext servletContext) {
39 | try {
40 | DbTablePrimaryKeyFieldConfig.buildKeyFieldsMap();
41 | } catch (Exception e) {
42 | e.printStackTrace();
43 | }
44 |
45 | }
46 |
47 |
48 | /**
49 | * 构建表与主键字段的对应关系
50 | * @throws Exception
51 | */
52 | private static void buildKeyFieldsMap() throws Exception {
53 | if(StringUtils.isEmpty(schemaName)) {
54 | throw new Exception("必须在config.properties中配置当前项目的数据schemaName,或直接配置schemaName的值");
55 | }
56 | if(conn==null) {
57 | conn=SpringContextHolder.getConnection();
58 | }
59 | String sql="SELECT\n" +
60 | " t.TABLE_NAME ,\n" +
61 | " max(c.COLUMN_NAME) AS NAME\n" +
62 | "FROM\n" +
63 | " information_schema.`COLUMNS` c\n" +
64 | " left join\n" +
65 | " INFORMATION_SCHEMA.TABLES t on t.TABLE_NAME=c.table_name \n" +
66 | "WHERE\n" +
67 | "c.COLUMN_KEY = 'PRI' and\n" +
68 | "c.TABLE_SCHEMA = '"+schemaName+"' and\n" +
69 | "t.table_schema = '"+schemaName+"'\n" +
70 | "group by t.TABLE_NAME";
71 | PreparedStatement pstmt = (PreparedStatement)conn.prepareStatement(sql);
72 | Map tableMap = Maps.newHashMap(); //存放字段
73 | ResultSet rs = pstmt.executeQuery();
74 | while (rs.next()){
75 | String a=rs.getString(1);// 表名
76 | String b=rs.getString(2);// 主键列名
77 | keyFieldsMap.put(a,StringUtils.toCamelCase(b));
78 |
79 | }
80 | }
81 | /**
82 | * 根据实体名获得主键字段名
83 | * @param entityName
84 | * @return
85 | */
86 | public static String findKeyField(String entityName) {
87 | entityName=StringUtils.firstToLower(entityName);
88 | String dbTableName=StringUtils.toUnderScoreCase(entityName);
89 | String startWithTb=keyFieldsMap.get(dbTableName);
90 | if(StringUtils.isEmpty(startWithTb)) {//如果找不到
91 | startWithTb=keyFieldsMap.getStringValue("tb_"+dbTableName,idFieldName);
92 | }
93 | return startWithTb;
94 | }
95 | /**
96 | * 根据实体对象获得主键字段名
97 | * @param entityName
98 | * @return
99 | */
100 | public static String findKeyField(TjBaseEntity be) {
101 | String entityName=JspElement.getEntityNameByClass(be.getClass(), false);
102 | return findKeyField(entityName);
103 | }
104 | /**
105 | * 根据实体类获得主键字段名
106 | * @param entityName
107 | * @return
108 | */
109 | public static String findKeyField(Class extends TjBaseEntity> beClass) {
110 | String entityName=JspElement.getEntityNameByClass(beClass, false);
111 | return findKeyField(entityName);
112 | }
113 | /**
114 | * 数据库表名获得主键字段名
115 | * @param entityName:带有tb的驼峰后的表名
116 | * @return
117 | */
118 | public static String findKeyFieldBytbName(String tbTableName) {
119 | String dbTableName=StringUtils.toUnderScoreCase(tbTableName);
120 | String dest=keyFieldsMap.getStringValue(dbTableName);
121 |
122 | return dest;
123 | }
124 | /**
125 | * 数据库表名获得主键字段名
126 | * @param entityName
127 | * @return
128 | */
129 | public static String findKeyFieldByDbName(String dbTableName) {
130 | String dest=keyFieldsMap.getStringValue(dbTableName);
131 |
132 | return dest;
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/persistence/util/JspElement.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.persistence.util;
2 |
3 | import java.lang.reflect.Field;
4 | import com.tengjie.common.utils.StringUtils;
5 |
6 |
7 | //
8 | //Date format:
9 | public abstract class JspElement {
10 |
11 | /**
12 | * 获得驼峰后的带有tb的名字,如tbTeacherInfo,但是对于user.java和老的一些程序,可能是没有_TB_TABLE_NAME_这个字段的,不能反射调用这个字段来获取
13 | */
14 | public static String findWithCamelTableName(Class tableClass,boolean iffirstup) {
15 |
16 | String simpleName=StringUtils.findClassSimpleName(tableClass, iffirstup);
17 |
18 |
19 | if(simpleName.toLowerCase().equals("user")) {//还有一些没有tb开头的表,这里都要加上
20 | return "sysUser";
21 | }else if(simpleName.toLowerCase().equals("appuser")) {//还有一些没有tb开头的表,这里都要加上
22 | Field ff=null;
23 | try {
24 | ff=tableClass.getDeclaredField("_TB_TABLE_NAME_");
25 | }catch(Exception e) {};
26 | if(ff!=null) {
27 | return "tbAppUser";
28 | }
29 | return "tbUser";
30 | }else {
31 | String tb=iffirstup?"Tb":"tb";
32 | return tb+StringUtils.firstToUpper(simpleName);
33 | }
34 | }
35 | /**
36 | * 根据表类或者表名,默认是获得首字小写的,iffirstup如果为true则表示要大写的
37 | * @param tableClass
38 | * @param iffirstup
39 | * @return
40 | */
41 | public static String getEntityNameByClass(Class tableClass,boolean ...iffirstup){
42 | String entityName=tableClass.getSimpleName();
43 | //如果是带有动态属性的bean,名字会不一样,是这样的teacherInfo$$BeanGeneratorByCGLIB$$33b233a6,这样无法覆盖原来的
44 | if(entityName.contains("$$"))entityName=entityName.substring(0, entityName.indexOf("$$"));
45 | boolean firstup=iffirstup.length>0?iffirstup[0]:false;
46 | if(!firstup){
47 | entityName=StringUtils.firstToLower(entityName);
48 | }
49 | return entityName;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/persistence/util/PrintDebugSql.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.persistence.util;
2 |
3 | import java.text.DateFormat;
4 | import java.util.Date;
5 | import java.util.List;
6 | import java.util.Locale;
7 | import java.util.regex.Matcher;
8 |
9 | import org.apache.commons.collections.CollectionUtils;
10 | import org.apache.ibatis.mapping.BoundSql;
11 | import org.apache.ibatis.mapping.ParameterMapping;
12 | import org.apache.ibatis.reflection.MetaObject;
13 | import org.apache.ibatis.session.Configuration;
14 | import org.apache.ibatis.type.TypeHandlerRegistry;
15 |
16 | public class PrintDebugSql {
17 | // 封装了一下sql语句,使得结果返回完整xml路径下的sql语句节点id + sql语句
18 | public static String getSql(Configuration configuration, BoundSql boundSql,
19 | String sqlId) {
20 | String sql = showSql(configuration, boundSql);
21 | return sql;
22 | }
23 |
24 | /**
25 | * 如果参数是String,则添加单引号, 如果是日期,则转换为时间格式器并加单引号; 对参数是null和不是null的情况作了处理
26 | */
27 | private static String getParameterValue(Object obj) {
28 | String value = null;
29 | if (obj instanceof String) {
30 | value = "'" + obj.toString() + "'";
31 | } else if (obj instanceof Date) {
32 | DateFormat formatter = DateFormat.getDateTimeInstance(
33 | DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.CHINA);
34 | value = "'" + formatter.format(obj) + "'";
35 | } else {
36 | if (obj != null) {
37 | value = obj.toString();
38 | } else {
39 | value = "";
40 | }
41 |
42 | }
43 | return value;
44 | }
45 |
46 | /**
47 | * 进行?的替换
48 | *
49 | * @param configuration
50 | * @param boundSql
51 | * @return
52 | */
53 | public static String showSql(Configuration configuration, BoundSql boundSql) {
54 | Object parameterObject = boundSql.getParameterObject(); // 获取参数
55 | List
parameterMappings = boundSql
56 | .getParameterMappings();
57 | String sql = boundSql.getSql().replaceAll("[\\s]+", " "); // sql语句中多个空格都用一个空格代替
58 | if (CollectionUtils.isNotEmpty(parameterMappings)
59 | && parameterObject != null) {
60 | TypeHandlerRegistry typeHandlerRegistry = configuration
61 | .getTypeHandlerRegistry(); // 获取类型处理器注册器,类型处理器的功能是进行java类型和数据库类型的转换 //
62 | // 如果根据parameterObject.getClass()可以找到对应的类型,则替换
63 | if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
64 | sql = sql.replaceFirst("\\?", Matcher
65 | .quoteReplacement(getParameterValue(parameterObject)));
66 |
67 | } else {
68 | MetaObject metaObject = configuration
69 | .newMetaObject(parameterObject);// MetaObject主要是封装了originalObject对象,提供了get和set的方法用于获取和设置originalObject的属性值,主要支持对JavaBean、Collection、Map三种类型对象的操作
70 | for (ParameterMapping parameterMapping : parameterMappings) {
71 | String propertyName = parameterMapping.getProperty();
72 | if (metaObject.hasGetter(propertyName)) {
73 | Object obj = metaObject.getValue(propertyName);
74 | sql = sql.replaceFirst("\\?", Matcher
75 | .quoteReplacement(getParameterValue(obj)));
76 | } else if (boundSql.hasAdditionalParameter(propertyName)) {
77 | Object obj = boundSql
78 | .getAdditionalParameter(propertyName); // 该分支是动态sql
79 | sql = sql.replaceFirst("\\?", Matcher
80 | .quoteReplacement(getParameterValue(obj)));
81 | } else {
82 | sql = sql.replaceFirst("\\?", "*!!!缺失值,请确认页面或者接口是否传递了该值");
83 | }// 打印出缺失,提醒该参数缺失并防止错位
84 | }
85 | }
86 | }
87 | return sql;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/persistence/util/QueryParamInfoVO.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.persistence.util;
2 |
3 | import java.util.List;
4 |
5 | import com.google.common.collect.Lists;
6 | import com.tengjie.common.persistence.TjBaseEntity;
7 | import com.tengjie.common.persistence.JoinTableBean;
8 | import com.tengjie.common.utils.Reflections;
9 |
10 | /**
11 | * 主要为了向某些动态方法中传递所需参数的名字、运算符、值等信息
12 | * 创建时时为了JoinTableBean的buildAnyCountJtb方法使用,因为entity不确定,因此要对这个bean进行哪些参数的传递需要依靠这个来传递
13 | * 后续,感觉这个可以应用到好多地方来进行参数的传递
14 | * @author admin
15 | *
16 | */
17 | public class QueryParamInfoVO {
18 | List paramList=Lists.newArrayList();
19 |
20 | public QueryParamInfoVO() {
21 | super();
22 | }
23 | public static void parseParam(TjBaseEntity dest,QueryParamInfoVO qpiv) {
24 | if(dest==null||qpiv==null)return;
25 | List childList=qpiv.paramList;
26 | for(QueryParamInfoVOChild child:childList) {
27 | String filedName=child.getFieldName();
28 | if(child.getValue()!=null)
29 | Reflections.invokeSetter(dest, filedName, child.getValue());
30 | if(RelationOperationTool.IN .equals(child.getRelationOperationSign())) {
31 | dest.putWhereIn(filedName, RelationOperationTool.IN);
32 |
33 | }else if(RelationOperationTool.NOT_IN.equals(child.getRelationOperationSign())) {
34 | dest.putWhereIn(filedName, RelationOperationTool.NOT_IN);
35 | }else if(RelationOperationTool.IS_NULL.equals(child.getRelationOperationSign())) {
36 | dest.putWhereISNULL(filedName, false);
37 |
38 | }else if(RelationOperationTool.IS_NOT_NULL.equals(child.getRelationOperationSign())) {
39 | dest.putWhereISNULL(filedName, true);
40 | }else if(RelationOperationTool.LIKE.equals(child.getRelationOperationSign())) {
41 | dest.putWhereLike(filedName);
42 | }else {
43 | dest.putRelationOper(filedName, child.getRelationOperationSign());
44 | }
45 |
46 | }
47 | }
48 | /**
49 | * 添加一条参数描述描述记录
50 | * @param fieldName:字段名
51 | * @param relationOperationSign:运算符,来自于RelationOperationTool
52 | * @param value:字段的值,可以为空
53 | * @return
54 | */
55 | public QueryParamInfoVO putInfo(String fieldName, String relationOperationSign, Object value) {
56 | QueryParamInfoVOChild child=new QueryParamInfoVOChild(fieldName,relationOperationSign,value);
57 | paramList.add(child);
58 | return this;
59 | }
60 | /**
61 | * 添加一条参数描述描述记录
62 | * @param fieldName:字段名
63 | * @param value:字段的值,可以为空
64 | * @return
65 | */
66 | public QueryParamInfoVO putInfo(String fieldName, Object value) {
67 | QueryParamInfoVOChild child=new QueryParamInfoVOChild(fieldName,value);
68 | paramList.add(child);
69 | return this;
70 | }
71 |
72 | public static QueryParamInfoVO newInstance(String fieldName, String relationOperationSign, Object value) {
73 | QueryParamInfoVO qp=new QueryParamInfoVO();
74 | qp.putInfo(fieldName, relationOperationSign, value);
75 | return qp;
76 | }
77 | public static QueryParamInfoVO newInstance(String fieldName, Object value) {
78 | QueryParamInfoVO qp=new QueryParamInfoVO();
79 | qp.putInfo(fieldName, value);
80 | return qp;
81 | }
82 | public static QueryParamInfoVO newInstance() {
83 | QueryParamInfoVO qp=new QueryParamInfoVO();
84 | return qp;
85 | }
86 | private static class QueryParamInfoVOChild{
87 | private String fieldName;
88 | private String relationOperationSign=RelationOperationTool.EQUAL;//来自于RelationOperationTool,默认时等于
89 | private Object value;
90 | private Object value1;// 为between准备,但是这里没有处理,后面需要再加
91 | public String getFieldName() {
92 | return fieldName;
93 | }
94 | public void setFieldName(String fieldName) {
95 | this.fieldName = fieldName;
96 | }
97 | public String getRelationOperationSign() {
98 | return relationOperationSign;
99 | }
100 | public void setRelationOperationSign(String relationOperationSign) {
101 | this.relationOperationSign = relationOperationSign;
102 | }
103 | public Object getValue() {
104 | return value;
105 | }
106 | public void setValue(Object value) {
107 | this.value = value;
108 | }
109 | public QueryParamInfoVOChild(String fieldName, String relationOperationSign, Object value) {
110 | super();
111 | this.fieldName = fieldName;
112 | if(relationOperationSign!=null)
113 | this.relationOperationSign = relationOperationSign;
114 | this.value = value;
115 | }
116 | public QueryParamInfoVOChild(String fieldName, Object value) {
117 | super();
118 | this.fieldName = fieldName;
119 | this.value = value;
120 | }
121 |
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/persistence/util/RelationOperationTool.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.persistence.util;
2 |
3 | public class RelationOperationTool {
4 | public static String EQUAL = " = ";
5 | public static String NOT_EQUAL = " != ";
6 | public static String BIG= " > ";
7 | public static String BIG_EQUAL = " >= ";
8 | public static String SMALL = " < ";
9 | public static String SMALL_EQUAL = " <= ";
10 |
11 | public static String IN = "IN";
12 | public static String NOT_IN = "NOT IN";
13 | public static String BETWEEN="BETWEEN";
14 | public static String IS_NULL="IS NULL";
15 | public static String IS_NOT_NULL="IS NOT NULL";
16 |
17 | public static String LIKE = " like ";
18 | }
19 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/persistence/util/ReturnTypeChangeUtil.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.persistence.util;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.List;
6 | import java.util.Map;
7 |
8 | import org.apache.ibatis.mapping.MappedStatement;
9 | import org.apache.ibatis.executor.Executor;
10 | import org.apache.ibatis.mapping.MappedStatement;
11 | import org.apache.ibatis.mapping.ResultMap;
12 | import org.apache.ibatis.mapping.ResultMapping;
13 | import org.apache.ibatis.plugin.*;
14 | import org.apache.ibatis.reflection.MetaObject;
15 | import org.apache.ibatis.reflection.SystemMetaObject;
16 | import org.apache.ibatis.session.ResultHandler;
17 | import org.apache.ibatis.session.RowBounds;
18 | /**
19 | * 此类作为工具类,服务于将返回值为bean的类型转换为Map类型,以便给接口使用
20 | * @author liangfeng
21 | *
22 | */
23 | public class ReturnTypeChangeUtil {
24 | private static final List EMPTY_RESULTMAPPING = new ArrayList(0);
25 | private static Map statementCache=new HashMap();
26 | /**
27 | * 根据现有的 ms 创建一个新的,使用新的返回值类型
28 | *
29 | * @param ms
30 | * @return
31 | */
32 | public static MappedStatement newMappedStatement(MappedStatement ms, Class resultType) {
33 | //下面是新建的过程,考虑效率和复用对象的情况下,这里最后生成的ms可以缓存起来,下次根据 ms.getId() + "_" + getShortName(resultType) 直接返回 ms,省去反复创建的过程
34 | String key=ms.getId() + "_Map";
35 | if( statementCache.get(key)!=null)return statementCache.get(key);
36 | MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), key, ms.getSqlSource(), ms.getSqlCommandType());
37 | builder.resource(ms.getResource());
38 | builder.fetchSize(ms.getFetchSize());
39 | builder.statementType(ms.getStatementType());
40 | builder.keyGenerator(ms.getKeyGenerator());
41 | if (ms.getKeyProperties() != null && ms.getKeyProperties().length != 0) {
42 | StringBuilder keyProperties = new StringBuilder();
43 | for (String keyProperty : ms.getKeyProperties()) {
44 | keyProperties.append(keyProperty).append(",");
45 | }
46 | keyProperties.delete(keyProperties.length() - 1, keyProperties.length());
47 | builder.keyProperty(keyProperties.toString());
48 | }
49 | builder.timeout(ms.getTimeout());
50 | builder.parameterMap(ms.getParameterMap());
51 | //count查询返回值int
52 | List resultMaps = new ArrayList();
53 | ResultMap resultMap = new ResultMap.Builder(ms.getConfiguration(), ms.getId(), resultType, EMPTY_RESULTMAPPING).build();
54 | resultMaps.add(resultMap);
55 | builder.resultMaps(resultMaps);
56 | builder.resultSetType(ms.getResultSetType());
57 | builder.cache(ms.getCache());
58 | builder.flushCacheRequired(ms.isFlushCacheRequired());
59 | builder.useCache(ms.isUseCache());
60 | MappedStatement temp=builder.build();
61 | statementCache.put(key, temp);
62 | return temp;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/service/BaseService.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.service;
2 |
3 |
4 | import java.util.Map;
5 |
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 | import org.springframework.transaction.annotation.Transactional;
9 |
10 | import com.tengjie.common.config.Global;
11 | import com.tengjie.common.persistence.TjBaseEntity;
12 | import com.tengjie.common.persistence.JoinTableBean;
13 | import com.tengjie.common.utils.Reflections;
14 | import com.tengjie.common.utils.StringUtils;
15 |
16 |
17 | /**
18 | * Service基类
19 | * @author
20 | * @version 2014-05-16
21 | */
22 | @Transactional(readOnly = true)
23 | public abstract class BaseService {
24 |
25 | /**
26 | * 日志对象
27 | */
28 | protected Logger logger = LoggerFactory.getLogger(getClass());
29 |
30 |
31 | /**
32 | * 快速获得关联表bean,此方法不支持需要主表别名情况
33 | * @param tableName 关联表名,注意加tb
34 | * @param mainRelFieldName 主表关联字段
35 | * @param childRelFieldName 字表关联字段
36 | * @param selectMap 字表select的字段列表
37 | * @return
38 | */
39 | public static JoinTableBean findJoinTableBean(String tableName,String mainRelFieldName,String childRelFieldName,Map selectMap){
40 | return findJoinTableBean(null,tableName,mainRelFieldName, childRelFieldName, selectMap);
41 | }
42 | /**
43 | * 快速获得关联表bean,此方法支持需要主表别名情况
44 | * @param mainTableAlias 主表的别名
45 | * @param tableName 关联表名,注意加tb
46 | * @param mainRelFieldName 主表关联字段
47 | * @param childRelFieldName 字表关联字段
48 | * @param selectMap 字表select的字段列表
49 | * @return
50 | */
51 | public static JoinTableBean findJoinTableBean(String mainTableAlias,String tableName,String mainRelFieldName,String childRelFieldName,Map selectMap){
52 | JoinTableBean jtb=new JoinTableBean();
53 | if(StringUtils.isNotEmpty(mainTableAlias))
54 | jtb.setMainTableName(mainTableAlias);
55 | jtb.setTableName(tableName);
56 | jtb.putOnCond(mainRelFieldName, childRelFieldName);
57 | if(selectMap!=null)
58 | for (Map.Entry entry : selectMap.entrySet()) {
59 | jtb.putSelect(entry.getKey(), StringUtils.isEmpty(entry.getValue())?entry.getKey():entry.getValue());
60 | }
61 | return jtb;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/service/ServiceException.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.service;
2 |
3 | /**
4 | * Service层公用的Exception, 从由Spring管理事务的函数中抛出时会触发事务回滚.
5 | * @author
6 | */
7 | public class ServiceException extends RuntimeException {
8 |
9 | private static final long serialVersionUID = 1L;
10 |
11 | public ServiceException() {
12 | super();
13 | }
14 |
15 | public ServiceException(String message) {
16 | super(message);
17 | }
18 |
19 | public ServiceException(Throwable cause) {
20 | super(cause);
21 | }
22 |
23 | public ServiceException(String message, Throwable cause) {
24 | super(message, cause);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/service/ServiceUtils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.service;
2 | import java.util.List;
3 |
4 | import com.tengjie.common.persistence.TjBaseEntity;
5 | import com.tengjie.common.utils.Reflections;
6 | import com.tengjie.common.utils.SpringContextHolder;
7 | import com.tengjie.common.utils.StringUtils;
8 |
9 | public class ServiceUtils {
10 | /**
11 | * 此方法创建的初衷是由于很两个表关联,比如B表中存储了A表中的id,查询出B表时,也要根据这个ID获得A表记录,请取得A表记录总的某个字段的值
12 | * 注意,传入的queryPropName和queryPropValue取得的结果集无论是多少条,只返回第一条对应的resultPropName所对应的值
13 | * 示例:实际sql为:select a.resultPropName from tableName a where a.queryPropName=queryPropValue;
14 | * @param tableName:要查询的表名,实际为实体bean名,如projectPlan
15 | * @param queryPropName 要查询的属性名
16 | * @param queryPropValue 要查询的属性名对应的值
17 | * @param resultPropName 要返回结果的属性
18 | * @return//
19 | */
20 | public static Object callTableByCondPorp(String tableName,String queryPropName,Object queryPropValue,String resultPropName){
21 | Object resultPropValue=null;
22 |
23 | TjBaseEntity de=callTableByCondBean(tableName,queryPropName,queryPropValue);
24 | if(de!=null){
25 | resultPropValue=Reflections.getFieldValue(de,resultPropName);
26 | }
27 |
28 | return resultPropValue;
29 | }
30 | /**
31 | * 此方法与callTableByCondPorp区别是,获得属性列表,传入的值应该是a,b,c,最后拼接成in('a','b','c',)
32 | * @return//
33 | */
34 | public static Object callTableByCondPorpIn(String tableName,String queryPropName,Object queryPropValue,String resultPropName){
35 | Object resultPropValue=null;
36 |
37 | TjBaseEntity de=callTableByCondBean(tableName,queryPropName,queryPropValue);
38 | if(de!=null){
39 | resultPropValue=Reflections.getFieldValue(de,resultPropName);
40 | }
41 |
42 | return resultPropValue;
43 | }
44 | /**
45 | * 此方法创建的初衷是由于很两个表关联,比如B表中存储了A表中的id,查询出B表时,也要根据这个ID获得A表记录,请取得A表记录总的某个字段的值
46 | * 注意,传入的queryPropName和queryPropValue取得的结果集无论是多少条,只返回第一条记录
47 | * 示例:实际sql为:select * from tableName a where a.queryPropName=queryPropValue;
48 | * @param tableName:要查询的表名,实际为实体bean名,如projectPlan
49 | * @param queryPropName 要查询的属性名
50 | * @param queryPropValue 要查询的属性名对应的值
51 | * @return DataEntity
52 | */
53 | public static TjBaseEntity callTableByCondBean(String tableName,String queryPropName,Object queryPropValue){
54 | TjBaseEntity oneRecord=null;
55 |
56 | //tableName=tableName.substring(0, 1).toUpperCase() + tableName.substring(1);
57 | if(queryPropValue==null||StringUtils.isEmpty(queryPropValue+""))return null;
58 | CrudService cService = (CrudService) SpringContextHolder.getBean(tableName+"Service");
59 | oneRecord=cService.findUniqueByProperty(queryPropName, queryPropValue);
60 |
61 | return oneRecord;
62 | }
63 | /**
64 | * 此方法创建的初衷是由于很两个表关联,比如B表中存储了A表中的id,查询出B表时,也要根据这个ID获得A表记录,请取得A表记录总的某个字段的值
65 | * 注意,传入的queryPropName和queryPropValue取得的结果集无论是多少条,只返回第一条记录
66 | * 示例:实际sql为:select * from tableName a where a.queryPropName=queryPropValue;
67 | * @param tableName:要查询的表名,实际为实体bean名,如projectPlan
68 | * @param queryPropName 要查询的属性名
69 | * @param queryPropValue 要查询的属性名对应的值
70 | * @return DataEntity
71 | */
72 | public static List callTableByCondList(String tableName,String queryPropName,Object queryPropValue){
73 | List record=null;
74 |
75 | //tableName=tableName.substring(0, 1).toUpperCase() + tableName.substring(1);
76 | if(queryPropValue==null||StringUtils.isEmpty(queryPropValue+""))return null;
77 | CrudService cService = (CrudService) SpringContextHolder.getBean(tableName+"Service");
78 | record=cService.findListByProperty(queryPropName, queryPropValue);
79 | return record;
80 | }
81 |
82 | /**
83 | * 此方法无任何条件,直接查询全部
84 | * @param tableName:要查询的表名,实际为实体bean名,如projectPlan
85 | * @return List
86 | */
87 | public static List callTableAllByCondList(String tableName){
88 | List record=null;
89 | CrudService cService = (CrudService) SpringContextHolder.getBean(tableName+"Service");
90 | //DataEntity be=SpringContextHolder.getBean(tableName);
91 | record=cService.findListByProperty("1", 1);
92 | return record;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/Base64Utils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | /**
4 | * @ClassName Base64Utils
5 | * @Description: TODO
6 | * @author:
7 | * @since: 2017年8月30日 下午5:34:01
8 | */
9 | public class Base64Utils {
10 |
11 | static private char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray();
12 | static private byte[] codes = new byte[256];
13 | static {
14 | for (int i = 0; i < 256; i++)
15 | codes[i] = -1;
16 | for (int i = 'A'; i <= 'Z'; i++)
17 | codes[i] = (byte) (i - 'A');
18 | for (int i = 'a'; i <= 'z'; i++)
19 | codes[i] = (byte) (26 + i - 'a');
20 | for (int i = '0'; i <= '9'; i++)
21 | codes[i] = (byte) (52 + i - '0');
22 | codes['+'] = 62;
23 | codes['/'] = 63;
24 | }
25 |
26 | /**
27 | * 将原始数据编码为base64编码
28 | */
29 | static public String encode(byte[] data) {
30 | char[] out = new char[((data.length + 2) / 3) * 4];
31 | for (int i = 0, index = 0; i < data.length; i += 3, index += 4) {
32 | boolean quad = false;
33 | boolean trip = false;
34 | int val = (0xFF & (int) data[i]);
35 | val <<= 8;
36 | if ((i + 1) < data.length) {
37 | val |= (0xFF & (int) data[i + 1]);
38 | trip = true;
39 | }
40 | val <<= 8;
41 | if ((i + 2) < data.length) {
42 | val |= (0xFF & (int) data[i + 2]);
43 | quad = true;
44 | }
45 | out[index + 3] = alphabet[(quad ? (val & 0x3F) : 64)];
46 | val >>= 6;
47 | out[index + 2] = alphabet[(trip ? (val & 0x3F) : 64)];
48 | val >>= 6;
49 | out[index + 1] = alphabet[val & 0x3F];
50 | val >>= 6;
51 | out[index + 0] = alphabet[val & 0x3F];
52 | }
53 |
54 | return new String(out);
55 | }
56 |
57 | /**
58 | * 将base64编码的数据解码成原始数据
59 | */
60 | static public byte[] decode(char[] data) {
61 | int len = ((data.length + 3) / 4) * 3;
62 | if (data.length > 0 && data[data.length - 1] == '=')
63 | --len;
64 | if (data.length > 1 && data[data.length - 2] == '=')
65 | --len;
66 | byte[] out = new byte[len];
67 | int shift = 0;
68 | int accum = 0;
69 | int index = 0;
70 | for (int ix = 0; ix < data.length; ix++) {
71 | int value = codes[data[ix] & 0xFF];
72 | if (value >= 0) {
73 | accum <<= 6;
74 | shift += 6;
75 | accum |= value;
76 | if (shift >= 8) {
77 | shift -= 8;
78 | out[index++] = (byte) ((accum >> shift) & 0xff);
79 | }
80 | }
81 | }
82 | if (index != out.length)
83 | throw new RuntimeException("miscalculated data length!");
84 | // throw new Error("miscalculated data length!");
85 |
86 | return out;
87 | }
88 | }
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/BigdecimalUtils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.math.BigDecimal;
4 |
5 | public class BigdecimalUtils {
6 | // 默认除法运算精度
7 | private static final int DEF_DIV_SCALE = 10;
8 |
9 | // 这个类不能实例化
10 | private BigdecimalUtils() {
11 |
12 | }
13 |
14 | /**
15 | * 提供精确的加法运算。
16 | *
17 | * @param v1
18 | * 被加数
19 | * @param v2
20 | * 加数
21 | * @return 两个参数的和
22 | */
23 |
24 | public static BigDecimal add(BigDecimal v1, BigDecimal v2) {
25 | return v1.add(v2);
26 | }
27 |
28 | /**
29 | * 提供精确的减法运算。
30 | *
31 | * @param v1
32 | * 被减数
33 | * @param v2
34 | * 减数
35 | * @return 两个参数的差
36 | */
37 |
38 | public static BigDecimal sub(BigDecimal v1, BigDecimal v2) {
39 | return v1.subtract(v2);
40 | }
41 |
42 | /**
43 | * 提供精确的乘法运算。
44 | *
45 | * @param v1
46 | * 被乘数
47 | * @param v2
48 | * 乘数
49 | * @return 两个参数的积
50 | */
51 |
52 | public static BigDecimal mul(BigDecimal v1, BigDecimal v2) {
53 | return v1.multiply(v2);
54 | }
55 |
56 | /**
57 | * 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 定精度,以后的数字四舍五入。
58 | *
59 | * @param v1
60 | * 被除数
61 | * @param v2
62 | * 除数
63 | * @param scale
64 | * 表示表示需要精确到小数点以后几位。
65 | * @return 两个参数的商
66 | */
67 |
68 | public static BigDecimal div(BigDecimal v1, BigDecimal v2, int scale) {
69 | return v1.divide(v2, scale, BigDecimal.ROUND_HALF_UP);
70 | }
71 |
72 | /**
73 | * 提供精确的小数位四舍五入处理。
74 | *
75 | * @param v
76 | * 需要四舍五入的数字
77 | * @param scale
78 | * 小数点后保留几位
79 | * @return 四舍五入后的结果
80 | */
81 |
82 | public static BigDecimal round(BigDecimal v, int scale) {
83 | BigDecimal one = new BigDecimal("1");
84 | return v.divide(one, scale, BigDecimal.ROUND_HALF_UP);
85 | }
86 |
87 | /**
88 | * 提供精确的向下取整
89 | *
90 | * @param v
91 | * 需要向下取整的数字
92 | * @param scale
93 | * 小数点后保留几位
94 | * @return 向下取整后的结果
95 | */
96 |
97 | public static BigDecimal rounDown(BigDecimal v, int scale) {
98 | BigDecimal one = new BigDecimal("1");
99 | return v.divide(one, scale, BigDecimal.ROUND_DOWN);
100 | }
101 |
102 | /**
103 | * 提供精确的向上取整
104 | *
105 | * @param v
106 | * 需要向上取整的数字
107 | * @param scale
108 | * 小数点后保留几位
109 | * @return 向上取整的结果
110 | */
111 |
112 | public static BigDecimal rounUp(BigDecimal v, int scale) {
113 | BigDecimal one = new BigDecimal("1");
114 | return v.divide(one, scale, BigDecimal.ROUND_UP);
115 | }
116 |
117 |
118 | /**
119 | * 提供精确的计算结果向下取整
120 | *
121 | * @param v1
122 | * 被除数
123 | * @param v2
124 | * 除数
125 | * @param scale
126 | * 小数点后保留几位
127 | * @return 向下取整后的结果
128 | */
129 |
130 | public static BigDecimal rounDown(BigDecimal v1,BigDecimal v2,int scale) {
131 | return v1.divide(v2, scale, BigDecimal.ROUND_DOWN);
132 | }
133 |
134 | /**
135 | * 提供精确的向上取整
136 | *
137 | * @param v1
138 | * 被除数
139 | * @param v2
140 | * 除数
141 | * @param scale
142 | * 小数点后保留几位
143 | * @return 向上取整的结果
144 | */
145 | public static BigDecimal rounUp(BigDecimal v1,BigDecimal v2,int scale) {
146 | return v1.divide(v2, scale, BigDecimal.ROUND_UP);
147 | }
148 |
149 | public static void main(String[] args) {
150 |
151 | BigDecimal v = new BigDecimal("1");
152 |
153 | BigDecimal one = new BigDecimal("1");
154 | BigDecimal s = v.divide(one, 10, BigDecimal.ROUND_HALF_UP);
155 |
156 | System.out.println(s);
157 | BigDecimal q = s.multiply(new BigDecimal("2"));
158 | System.out.println(q);
159 |
160 | BigDecimal two = new BigDecimal("1");
161 | BigDecimal s1 = q.divide(two, 10, BigDecimal.ROUND_HALF_UP);
162 | System.out.println(s1);
163 | BigDecimal s2 = s1.multiply(new BigDecimal("1"));
164 | System.out.println(s2);
165 | BigDecimal s3 = s2.divide(new BigDecimal("1"), 1, BigDecimal.ROUND_DOWN);
166 | System.out.println(s3);
167 | }
168 |
169 | }
170 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/CacheUtils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.lang.reflect.Field;
4 | import java.lang.reflect.Method;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | import net.sf.ehcache.Cache;
10 | import net.sf.ehcache.CacheManager;
11 | import net.sf.ehcache.Element;
12 |
13 | /**
14 | * Cache工具类
15 | * @author
16 | * @version 2013-5-29
17 | */
18 | public class CacheUtils {
19 |
20 | private static CacheManager cacheManager = ((CacheManager)SpringContextHolder.getBean("cacheManager"));
21 |
22 | private static final String SYS_CACHE = "sysCache";
23 |
24 | /**
25 | * 获取SYS_CACHE缓存
26 | * @param key
27 | * @return
28 | */
29 | public static Object get(String key) {
30 | return get(SYS_CACHE, key);
31 | }
32 |
33 | /**
34 | * 写入SYS_CACHE缓存
35 | * @param key
36 | * @return
37 | */
38 | public static void put(String key, Object value) {
39 | put(SYS_CACHE, key, value);
40 | }
41 |
42 | /**
43 | * 从SYS_CACHE缓存中移除
44 | * @param key
45 | * @return
46 | */
47 | public static void remove(String key) {
48 | remove(SYS_CACHE, key);
49 | }
50 | /**
51 | * 获取缓存
52 | * @param cacheName
53 | * @param key
54 | * @return
55 | */
56 | public static List getByProperty(String cacheName, String propertyName,Object propertyValue) {
57 | Cache ca=getCache(cacheName);
58 | List result=new ArrayList();
59 | if(StringUtils.isEmpty(propertyName)||StringUtils.isEmpty(propertyValue+""))return result;
60 | Map element = ca.getAll(ca.getKeys());
61 |
62 | if(element!=null)
63 | for(Element e:element.values()){
64 | try {
65 | Field field=e.getClass().getDeclaredField(propertyName);
66 | if(field!=null){
67 | Object value= field.get(e);
68 | if(field.getType() == String.class){//后续应该加上其他类型的比较,这里先比较string
69 | if(value!=null&&propertyValue!=null){
70 | if(value.toString().equals(propertyValue)){
71 | result.add(e);
72 | }
73 | }
74 | }
75 | }
76 |
77 | } catch (NoSuchFieldException e1) {
78 | // e1.printStackTrace();
79 | break;
80 | } catch (SecurityException e1) {
81 | // TODO Auto-generated catch block
82 | e1.printStackTrace();
83 | } catch (IllegalArgumentException e1) {
84 | // TODO Auto-generated catch block
85 | e1.printStackTrace();
86 | } catch (IllegalAccessException e1) {
87 | // TODO Auto-generated catch block
88 | e1.printStackTrace();
89 | }
90 | e.getObjectValue();
91 | }
92 | return result;
93 | }
94 |
95 | /**
96 | * 获取缓存
97 | * @param cacheName
98 | * @param key
99 | * @return
100 | */
101 | public static Object get(String cacheName, String key) {
102 | Element element = getCache(cacheName).get(key);
103 | return element==null?null:element.getObjectValue();
104 | }
105 |
106 | /**
107 | * 写入缓存
108 | * @param cacheName
109 | * @param key
110 | * @param value
111 | */
112 | public static void put(String cacheName, String key, Object value) {
113 | Element element = new Element(key, value);
114 | getCache(cacheName).put(element);
115 | }
116 |
117 | /**
118 | * 从缓存中移除
119 | * @param cacheName
120 | * @param key
121 | */
122 | public static void remove(String cacheName, String key) {
123 | getCache(cacheName).remove(key);
124 | }
125 |
126 | /**
127 | * 获得一个Cache,没有则创建一个。
128 | * @param cacheName
129 | * @return
130 | */
131 | private static Cache getCache(String cacheName){
132 | Cache cache = cacheManager.getCache(cacheName);
133 | if (cache == null){
134 | cacheManager.addCache(cacheName);
135 | cache = cacheManager.getCache(cacheName);
136 | cache.getCacheConfiguration().setEternal(true);
137 | }
138 | return cache;
139 | }
140 |
141 | public static CacheManager getCacheManager() {
142 | return cacheManager;
143 | }
144 |
145 | }
146 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/CallBackBean.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 | import java.util.Arrays;
6 | import java.util.List;
7 |
8 | import com.tengjie.common.persistence.DataEntityFieldCallBackBean;
9 |
10 | public class CallBackBean implements Serializable {
11 | private static final long serialVersionUID = 1L;
12 | private String className;//对于在spring环境中的类,可以只是一个类名,否则必须带全路径的包名
13 | private String methodName;//方法 名,对于导入
14 | private Object[] otherParam;//其他传入的参数
15 |
16 | public CallBackBean(
17 | Object currObj, String methodName,Object[] otherParam) {
18 | super();
19 | this.className = StringUtils.firstToLower(currObj.getClass().getSimpleName());
20 | this.methodName = methodName;
21 | this.otherParam=otherParam;
22 | }
23 | public CallBackBean(String className, String methodName, Object[] otherParam) {
24 | super();
25 | this.className = className;
26 | this.methodName = methodName;
27 | this.otherParam = otherParam;
28 | }
29 | public String getClassName() {
30 | return className;
31 | }
32 | public void setClassName(String className) {
33 | this.className = className;
34 | }
35 | public String getMethodName() {
36 | return methodName;
37 | }
38 | public void setMethodName(String methodName) {
39 | this.methodName = methodName;
40 | }
41 | public Object[] getOtherParam() {
42 | return otherParam;
43 | }
44 | public void setOtherParam(Object[] otherParam) {
45 | this.otherParam = otherParam;
46 | }
47 | public static Object genCallBackBean(CallBackBean cbb) throws Exception{
48 | Object obj=findCallBackClass(cbb);
49 | return Reflections.invokeMethodByName(obj, cbb.getMethodName(),cbb.getOtherParam());
50 | }
51 | private static Object findCallBackClass(CallBackBean defcbb)throws Exception{
52 | String className=defcbb.getClassName();
53 | Object obj=null;
54 | try{
55 | obj=SpringContextHolder.getBean(className);
56 | }catch(Exception ex){
57 | char[] ch = className.toCharArray();
58 | if (ch[0] >= 'A' && ch[0] <= 'Z') {
59 | System.out.println("在当前spring环境中找不到" + className+ "对应的类,请将首字母小写!");
60 | } else {
61 | System.out.println("在当前spring环境中找不到" + className+ "对应的类,若该类不在spring环境中,请输入完整的包名+类名!");
62 | }
63 | }
64 | if(obj==null){
65 | obj=Class.forName(className).newInstance();
66 | }
67 | if (obj == null)
68 | throw new ClassNotFoundException("找不到]" + className+ "]对应的类,请核对是否正确!");
69 | return obj;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/CookieUtils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.URLDecoder;
5 | import java.net.URLEncoder;
6 |
7 | import javax.servlet.http.Cookie;
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 |
11 | /**
12 | * Cookie工具类
13 | * @author
14 | * @version 2013-01-15
15 | */
16 | public class CookieUtils {
17 |
18 | /**
19 | * 设置 Cookie(生成时间为1天)
20 | * @param name 名称
21 | * @param value 值
22 | */
23 | public static void setCookie(HttpServletResponse response, String name, String value) {
24 | setCookie(response, name, value, 60*60*24);
25 | }
26 |
27 | /**
28 | * 设置 Cookie
29 | * @param name 名称
30 | * @param value 值
31 | * @param maxAge 生存时间(单位秒)
32 | * @param uri 路径
33 | */
34 | public static void setCookie(HttpServletResponse response, String name, String value, String path) {
35 | setCookie(response, name, value, path, 60*60*24);
36 | }
37 |
38 | /**
39 | * 设置 Cookie
40 | * @param name 名称
41 | * @param value 值
42 | * @param maxAge 生存时间(单位秒)
43 | * @param uri 路径
44 | */
45 | public static void setCookie(HttpServletResponse response, String name, String value, int maxAge) {
46 | setCookie(response, name, value, "/", maxAge);
47 | }
48 |
49 | /**
50 | * 设置 Cookie
51 | * @param name 名称
52 | * @param value 值
53 | * @param maxAge 生存时间(单位秒)
54 | * @param uri 路径
55 | */
56 | public static void setCookie(HttpServletResponse response, String name, String value, String path, int maxAge) {
57 | Cookie cookie = new Cookie(name, null);
58 | cookie.setPath(path);
59 | cookie.setMaxAge(maxAge);
60 | try {
61 | cookie.setValue(URLEncoder.encode(value, "utf-8"));
62 | } catch (UnsupportedEncodingException e) {
63 | e.printStackTrace();
64 | }
65 | response.addCookie(cookie);
66 | }
67 |
68 | /**
69 | * 获得指定Cookie的值
70 | * @param name 名称
71 | * @return 值
72 | */
73 | public static String getCookie(HttpServletRequest request, String name) {
74 | return getCookie(request, null, name, false);
75 | }
76 | /**
77 | * 获得指定Cookie的值,并删除。
78 | * @param name 名称
79 | * @return 值
80 | */
81 | public static String getCookie(HttpServletRequest request, HttpServletResponse response, String name) {
82 | return getCookie(request, response, name, true);
83 | }
84 | /**
85 | * 获得指定Cookie的值
86 | * @param request 请求对象
87 | * @param response 响应对象
88 | * @param name 名字
89 | * @param isRemove 是否移除
90 | * @return 值
91 | */
92 | public static String getCookie(HttpServletRequest request, HttpServletResponse response, String name, boolean isRemove) {
93 | String value = null;
94 | Cookie[] cookies = request.getCookies();
95 | if (cookies != null) {
96 | for (Cookie cookie : cookies) {
97 | if (cookie.getName().equals(name)) {
98 | try {
99 | value = URLDecoder.decode(cookie.getValue(), "utf-8");
100 | } catch (UnsupportedEncodingException e) {
101 | e.printStackTrace();
102 | }
103 | if (isRemove) {
104 | cookie.setMaxAge(0);
105 | response.addCookie(cookie);
106 | }
107 | }
108 | }
109 | }
110 | return value;
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/EhCacheUtils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import net.sf.ehcache.Cache;
4 | import net.sf.ehcache.CacheManager;
5 | import net.sf.ehcache.Element;
6 |
7 | /**
8 | * Cache工具类
9 | * @author
10 | * @version 2013-5-29
11 | */
12 | public class EhCacheUtils {
13 |
14 | private static CacheManager cacheManager = ((CacheManager)SpringContextHolder.getBean("cacheManager"));
15 |
16 | private static final String SYS_CACHE = "sysCache";
17 |
18 | /**
19 | * 获取SYS_CACHE缓存
20 | * @param key
21 | * @return
22 | */
23 | public static Object get(String key) {
24 | return get(SYS_CACHE, key);
25 | }
26 |
27 | /**
28 | * 写入SYS_CACHE缓存
29 | * @param key
30 | * @return
31 | */
32 | public static void put(String key, Object value) {
33 | put(SYS_CACHE, key, value);
34 | }
35 |
36 | /**
37 | * 从SYS_CACHE缓存中移除
38 | * @param key
39 | * @return
40 | */
41 | public static void remove(String key) {
42 | remove(SYS_CACHE, key);
43 | }
44 |
45 | /**
46 | * 获取缓存
47 | * @param cacheName
48 | * @param key
49 | * @return
50 | */
51 | public static Object get(String cacheName, String key) {
52 | Element element = getCache(cacheName).get(key);
53 | return element==null?null:element.getObjectValue();
54 | }
55 |
56 | /**
57 | * 写入缓存
58 | * @param cacheName
59 | * @param key
60 | * @param value
61 | */
62 | public static void put(String cacheName, String key, Object value) {
63 | Element element = new Element(key, value);
64 | getCache(cacheName).put(element);
65 | }
66 |
67 | /**
68 | * 从缓存中移除
69 | * @param cacheName
70 | * @param key
71 | */
72 | public static void remove(String cacheName, String key) {
73 | getCache(cacheName).remove(key);
74 | }
75 |
76 | /**
77 | * 获得一个Cache,没有则创建一个。
78 | * @param cacheName
79 | * @return
80 | */
81 | private static Cache getCache(String cacheName){
82 | Cache cache = cacheManager.getCache(cacheName);
83 | if (cache == null){
84 | cacheManager.addCache(cacheName);
85 | cache = cacheManager.getCache(cacheName);
86 | cache.getCacheConfiguration().setEternal(true);
87 | }
88 | return cache;
89 | }
90 |
91 | public static CacheManager getCacheManager() {
92 | return cacheManager;
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/Encodes.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.io.UnsupportedEncodingException;
4 | import java.net.URLDecoder;
5 | import java.net.URLEncoder;
6 |
7 | import org.apache.commons.codec.DecoderException;
8 | import org.apache.commons.codec.binary.Base64;
9 | import org.apache.commons.codec.binary.Hex;
10 | import org.apache.commons.lang3.StringEscapeUtils;
11 |
12 | /**
13 | * 封装各种格式的编码解码工具类.
14 | * 1.Commons-Codec的 hex/base64 编码
15 | * 2.自制的base62 编码
16 | * 3.Commons-Lang的xml/html escape
17 | * 4.JDK提供的URLEncoder
18 | * @author
19 | * @version 2013-01-15
20 | */
21 | public class Encodes {
22 |
23 | private static final String DEFAULT_URL_ENCODING = "UTF-8";
24 | private static final char[] BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
25 |
26 | /**
27 | * Hex编码.
28 | */
29 | public static String encodeHex(byte[] input) {
30 | return new String(Hex.encodeHex(input));
31 | }
32 |
33 | /**
34 | * Hex解码.
35 | */
36 | public static byte[] decodeHex(String input) {
37 | try {
38 | return Hex.decodeHex(input.toCharArray());
39 | } catch (DecoderException e) {
40 | throw Exceptions.unchecked(e);
41 | }
42 | }
43 |
44 | /**
45 | * Base64编码.
46 | */
47 | public static String encodeBase64(byte[] input) {
48 | return new String(Base64.encodeBase64(input));
49 | }
50 |
51 | /**
52 | * Base64编码.
53 | */
54 | public static String encodeBase64(String input) {
55 | try {
56 | return new String(Base64.encodeBase64(input.getBytes(DEFAULT_URL_ENCODING)));
57 | } catch (UnsupportedEncodingException e) {
58 | return "";
59 | }
60 | }
61 |
62 | // /**
63 | // * Base64编码, URL安全(将Base64中的URL非法字符'+'和'/'转为'-'和'_', 见RFC3548).
64 | // */
65 | // public static String encodeUrlSafeBase64(byte[] input) {
66 | // return Base64.encodeBase64URLSafe(input);
67 | // }
68 |
69 | /**
70 | * Base64解码.
71 | */
72 | public static byte[] decodeBase64(String input) {
73 | return Base64.decodeBase64(input.getBytes());
74 | }
75 |
76 | /**
77 | * Base64解码.
78 | */
79 | public static String decodeBase64String(String input) {
80 | try {
81 | return new String(Base64.decodeBase64(input.getBytes()), DEFAULT_URL_ENCODING);
82 | } catch (UnsupportedEncodingException e) {
83 | return "";
84 | }
85 | }
86 |
87 | /**
88 | * Base62编码。
89 | */
90 | public static String encodeBase62(byte[] input) {
91 | char[] chars = new char[input.length];
92 | for (int i = 0; i < input.length; i++) {
93 | chars[i] = BASE62[((input[i] & 0xFF) % BASE62.length)];
94 | }
95 | return new String(chars);
96 | }
97 |
98 | /**
99 | * Html 转码.
100 | */
101 | public static String escapeHtml(String html) {
102 | return StringEscapeUtils.escapeHtml4(html);
103 | }
104 |
105 | /**
106 | * Html 解码.
107 | */
108 | public static String unescapeHtml(String htmlEscaped) {
109 | return StringEscapeUtils.unescapeHtml4(htmlEscaped);
110 | }
111 |
112 | /**
113 | * Xml 转码.
114 | */
115 | public static String escapeXml(String xml) {
116 | return StringEscapeUtils.escapeXml10(xml);
117 | }
118 |
119 | /**
120 | * Xml 解码.
121 | */
122 | public static String unescapeXml(String xmlEscaped) {
123 | return StringEscapeUtils.unescapeXml(xmlEscaped);
124 | }
125 |
126 | /**
127 | * URL 编码, Encode默认为UTF-8.
128 | */
129 | public static String urlEncode(String part) {
130 | try {
131 | return URLEncoder.encode(part, DEFAULT_URL_ENCODING);
132 | } catch (UnsupportedEncodingException e) {
133 | throw Exceptions.unchecked(e);
134 | }
135 | }
136 |
137 | /**
138 | * URL 解码, Encode默认为UTF-8.
139 | */
140 | public static String urlDecode(String part) {
141 |
142 | try {
143 | return URLDecoder.decode(part, DEFAULT_URL_ENCODING);
144 | } catch (UnsupportedEncodingException e) {
145 | throw Exceptions.unchecked(e);
146 | }
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/Exceptions.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.io.PrintWriter;
4 | import java.io.StringWriter;
5 |
6 | import javax.servlet.http.HttpServletRequest;
7 |
8 | /**
9 | * 关于异常的工具类.
10 | * @author
11 | * @version 2013-01-15
12 | */
13 | public class Exceptions {
14 |
15 | /**
16 | * 将CheckedException转换为UncheckedException.
17 | */
18 | public static RuntimeException unchecked(Exception e) {
19 | if (e instanceof RuntimeException) {
20 | return (RuntimeException) e;
21 | } else {
22 | return new RuntimeException(e);
23 | }
24 | }
25 |
26 | /**
27 | * 将ErrorStack转化为String.
28 | */
29 | public static String getStackTraceAsString(Throwable e) {
30 | if (e == null){
31 | return "";
32 | }
33 | StringWriter stringWriter = new StringWriter();
34 | e.printStackTrace(new PrintWriter(stringWriter));
35 | return stringWriter.toString();
36 | }
37 |
38 | /**
39 | * 判断异常是否由某些底层的异常引起.
40 | */
41 | public static boolean isCausedBy(Exception ex, Class extends Exception>... causeExceptionClasses) {
42 | Throwable cause = ex.getCause();
43 | while (cause != null) {
44 | for (Class extends Exception> causeClass : causeExceptionClasses) {
45 | if (causeClass.isInstance(cause)) {
46 | return true;
47 | }
48 | }
49 | cause = cause.getCause();
50 | }
51 | return false;
52 | }
53 |
54 | /**
55 | * 在request中获取异常类
56 | * @param request
57 | * @return
58 | */
59 | public static Throwable getThrowable(HttpServletRequest request){
60 | Throwable ex = null;
61 | if (request.getAttribute("exception") != null) {
62 | ex = (Throwable) request.getAttribute("exception");
63 | } else if (request.getAttribute("javax.servlet.error.exception") != null) {
64 | ex = (Throwable) request.getAttribute("javax.servlet.error.exception");
65 | }
66 | return ex;
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/FileDescEntity.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | /**
4 | * 文件描述
5 | * @author wangxipeng
6 | *
7 | */
8 | public class FileDescEntity {
9 |
10 | String saveName;//保存名
11 | String originalName;//原始名
12 | String fileContentType;
13 | String fileExtend;//文件后缀.docx .txt .jpg等
14 | String url;
15 | String contentType;//内容类型 如txt为 txt/plain
16 | int fileSize;
17 | String targetType;//1本地2云服务器
18 |
19 |
20 |
21 | public String getTargetType() {
22 | return targetType;
23 | }
24 |
25 | public void setTargetType(String targetType) {
26 | this.targetType = targetType;
27 | }
28 |
29 | public String getContentType() {
30 | return contentType;
31 | }
32 |
33 | public void setContentType(String contentType) {
34 | this.contentType = contentType;
35 | }
36 |
37 | public String getSaveName() {
38 | return saveName;
39 | }
40 |
41 | public void setSaveName(String saveName) {
42 | this.saveName = saveName;
43 | }
44 |
45 | public String getOriginalName() {
46 | return originalName;
47 | }
48 |
49 | public void setOriginalName(String originalName) {
50 | this.originalName = originalName;
51 | }
52 |
53 | public String getFileContentType() {
54 | return fileContentType;
55 | }
56 |
57 | public void setFileContentType(String fileContentType) {
58 | this.fileContentType = fileContentType;
59 | }
60 |
61 | public String getFileExtend() {
62 | return fileExtend;
63 | }
64 |
65 | public void setFileExtend(String fileExtend) {
66 | this.fileExtend = fileExtend;
67 | }
68 |
69 | public String getUrl() {
70 | return url;
71 | }
72 |
73 | public void setUrl(String url) {
74 | this.url = url;
75 | }
76 |
77 | public int getFileSize() {
78 | return fileSize;
79 | }
80 |
81 | public void setFileSize(int fileSize) {
82 | this.fileSize = fileSize;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/FileSizeHelper.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.text.DecimalFormat;
4 |
5 | /**
6 | *
7 | * 文件大小工具类.
8 | *
9 | *
10 | * @author
11 | * @version 1.0 2013-01-02 12:50 PM
12 | * @since JDK 1.5
13 | */
14 | public class FileSizeHelper {
15 | public static long ONE_KB = 1024;
16 | public static long ONE_MB = ONE_KB * 1024;
17 | public static long ONE_GB = ONE_MB * 1024;
18 | public static long ONE_TB = ONE_GB * (long)1024;
19 | public static long ONE_PB = ONE_TB * (long)1024;
20 |
21 | public static String getHumanReadableFileSize(Long fileSize) {
22 | if(fileSize == null) return null;
23 | return getHumanReadableFileSize(fileSize.longValue());
24 | }
25 |
26 | public static String getHumanReadableFileSize(long fileSize) {
27 | if(fileSize < 0) {
28 | return String.valueOf(fileSize);
29 | }
30 | String result = getHumanReadableFileSize(fileSize, ONE_PB, "PB");
31 | if(result != null) {
32 | return result;
33 | }
34 |
35 | result = getHumanReadableFileSize(fileSize, ONE_TB, "TB");
36 | if(result != null) {
37 | return result;
38 | }
39 | result = getHumanReadableFileSize(fileSize, ONE_GB, "GB");
40 | if(result != null) {
41 | return result;
42 | }
43 | result = getHumanReadableFileSize(fileSize, ONE_MB, "MB");
44 | if(result != null) {
45 | return result;
46 | }
47 | result = getHumanReadableFileSize(fileSize, ONE_KB, "KB");
48 | if(result != null) {
49 | return result;
50 | }
51 | return String.valueOf(fileSize)+"B";
52 | }
53 |
54 | private static String getHumanReadableFileSize(long fileSize, long unit, String unitName) {
55 | if(fileSize == 0) return "0";
56 |
57 | if(fileSize / unit >= 1) {
58 | double value = fileSize / (double)unit;
59 | DecimalFormat df = new DecimalFormat("######.##"+unitName);
60 | return df.format(value);
61 | }
62 | return null;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/FreeMarkerException.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | public class FreeMarkerException extends RuntimeException {
4 |
5 | public FreeMarkerException() {
6 | super();
7 | // TODO Auto-generated constructor stub
8 | }
9 |
10 | public FreeMarkerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
11 | super(message, cause, enableSuppression, writableStackTrace);
12 | // TODO Auto-generated constructor stub
13 | }
14 |
15 | public FreeMarkerException(String message, Throwable cause) {
16 | super(message, cause);
17 | // TODO Auto-generated constructor stub
18 | }
19 |
20 | public FreeMarkerException(String message) {
21 | super(message);
22 | // TODO Auto-generated constructor stub
23 | }
24 |
25 | public FreeMarkerException(Throwable cause) {
26 | super(cause);
27 | // TODO Auto-generated constructor stub
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/FreeMarkers.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.io.IOException;
4 | import java.io.StringReader;
5 | import java.io.StringWriter;
6 | import java.util.Map;
7 |
8 | import org.springframework.core.io.ClassPathResource;
9 | import org.springframework.core.io.DefaultResourceLoader;
10 | import org.springframework.core.io.Resource;
11 |
12 | import freemarker.template.Configuration;
13 | import freemarker.template.Template;
14 | import freemarker.template.TemplateException;
15 |
16 | /**
17 | * FreeMarkers工具类
18 | * @author
19 | * @version 2013-01-15
20 | */
21 | public class FreeMarkers {
22 | /**
23 | *
24 | * @param templateString:模板文件中的内容
25 | * @param model:赋值的模型
26 | * @param includePath:对于模板中如果有include,那么这个是指定include的模板文件从classpath下的哪个路径开始
27 | * 可变参数,实际只要一个,可以为空,为空的话,默认使用从class路径下的templates开始,即<#include "/apicloud/html/function/commonFunction.ftl">
28 | * apicloud是跟在templates后面的第一个目录。
29 | * @return
30 | * @throws Exception
31 | */
32 | public static String renderString(String templateString, Map model,String ...includePath) throws Exception {
33 | try{
34 | StringWriter result = new StringWriter();
35 | Configuration config=new Configuration();
36 | if(includePath.length<1) {
37 | config.setDirectoryForTemplateLoading(FileUtils.findClassPathFile("templates"));
38 | }else {
39 | config.setDirectoryForTemplateLoading(FileUtils.findClassPathFile(includePath[0]));
40 | }
41 | String freemarkerFileName=model.get("freemarkerFileName")==null?"name":model.get("freemarkerFileName").toString();//freemarker的配置中的name名字
42 | Template t = new Template(freemarkerFileName, new StringReader(templateString), config);
43 | t.process(model, result);
44 | return result.toString();
45 | } catch (Exception e) {
46 | throw new FreeMarkerException("根据数据向freemark赋值时出错:"+e.getMessage());
47 | }
48 | }
49 |
50 | public static String renderTemplate(Template template, Object model) {
51 | try {
52 | StringWriter result = new StringWriter();
53 | template.process(model, result);
54 | return result.toString();
55 | } catch (Exception e) {
56 | throw Exceptions.unchecked(e);
57 | }
58 | }
59 |
60 | public static Configuration buildConfiguration(String directory) throws IOException {
61 | Configuration cfg = new Configuration();
62 | Resource path = new DefaultResourceLoader().getResource(directory);
63 | cfg.setDirectoryForTemplateLoading(path.getFile());
64 | return cfg;
65 | }
66 |
67 | public static void main(String[] args) throws IOException {
68 | // // renderString
69 | // Map model = com.google.common.collect.Maps.newHashMap();
70 | // model.put("userName", "calvin");
71 | // String result = FreeMarkers.renderString("hello ${userName}", model);
72 | // System.out.println(result);
73 | // // renderTemplate
74 | // Configuration cfg = FreeMarkers.buildConfiguration("classpath:/");
75 | // Template template = cfg.getTemplate("testTemplate.ftl");
76 | // String result2 = FreeMarkers.renderTemplate(template, model);
77 | // System.out.println(result2);
78 |
79 | // Map model = com.google.common.collect.Maps.newHashMap();
80 | // model.put("userName", "calvin");
81 | // String result = FreeMarkers.renderString("hello ${userName} ${r'${userName}'}", model);
82 | // System.out.println(result);
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/GlobalStaticDictBase.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | public abstract class GlobalStaticDictBase {
4 |
5 | }
6 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/GlobalUtils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | /**
4 | * Created by hzl on 2017/7/6.
5 | */
6 | public final class GlobalUtils {
7 | //失败
8 | public static final String fail = "00";
9 | //成功
10 | public static final String suc = "01";
11 | //提示消息
12 | public static final String prompt = "02";
13 | //token失效
14 | public static final String tokenExp = "03";
15 | //签名错误
16 | public static final String signExp = "04";
17 | //时间戳超时
18 | public static final String timeExp = "05";
19 | //不合法参数
20 | public static final String validExp = "06";
21 | //验证码已失效
22 | public static final String codeExp = "07";
23 | //未注册
24 | public static final String regExp = "08";
25 | //已注册
26 | public static final String regedExp = "09";
27 | public static final String codeError = "10";
28 |
29 |
30 |
31 | //系统内部错误
32 | public static final String failMsg = "系统内部错误!";
33 | public static final String promptMsg = "报文参数错误!";
34 | public static final String sucMsg = "请求成功!";
35 | public static final String tokenMsg = "Token失效,重新登录!";
36 | public static final String signMsg = "访问签名错误!";
37 | public static final String timestampMsg = "时间戳超过30分钟!";
38 | public static final String validMsg = "不合法参数";
39 | public static final String codeMsg = "验证码失效!";
40 | public static final String regMsg= "该帐号未注册!";
41 | public static final String regedMsg= "该帐号已经注册!";
42 | public static final String codeErrorMsg= "验证码错误!";
43 | public static final String pwdMsg= "房间密码错误!";
44 | public static final String typeMsg = "操作类型不正确!";
45 |
46 | /**************************************************************************/
47 |
48 | /*返回status状态码 start*/
49 | //成功返回状态。
50 | public static final String status200 = "200";
51 | //用户发出的请求有误,服务器没有进行数据的操作。
52 | public static final String status400 = "400";
53 | //用户发出的请求针对的是不存在的记录,服务器没有进行操作。
54 | public static final String status404 = "404";
55 | //服务器发生错误,操作失败。
56 | public static final String status500 = "500";
57 | //手机号未注册
58 | public static final String status501 = "501";
59 | //密码错误
60 | public static final String status502 = "502";
61 | //验证码发送频繁
62 | public static final String status503 = "503";
63 | //验证码错误
64 | public static final String status504 = "504";
65 | //用户未注册
66 | public static final String status505 = "505";
67 | //密码错误
68 | public static final String status506 = "506";
69 | //用户权限验证失败
70 | public static final String status4001 = "4001";
71 | //用户权限不足
72 | public static final String status4002= "4002";
73 | //账号另一处登录
74 | public static final String status5001= "5001";
75 | /*返回status状态码 end*/
76 |
77 | /*短信类型 start*/
78 | //01:用户注册
79 | public static final String messType01 = "01";
80 | //02:用户验证码登录
81 | public static final String messType02 = "02";
82 | //03:修改密码
83 | public static final String messType03 = "03";
84 | //04:添加银行卡
85 | public static final String messType04 = "04";
86 | //05:第三方绑定手机号
87 | public static final String messType05 = "05";
88 | /*短信类型 end*/
89 |
90 | /*用户类型 01:房客02:房主start*/
91 | public static final String userType01="01";
92 | public static final String userType02="02";
93 | /*用户类型 end*/
94 |
95 | /*公共是否 1:是2:否start*/
96 | public static final String isType1="1";
97 | public static final String isType2="2";
98 | /*公共是否 end*/
99 |
100 | /*原来ErrorCodeConstant中的内容,具体错误的细项,现有statuscode,然后这个是详细的错误码描述*/
101 | public static final String ERROR_CODE = "16";
102 | public static final String ERROR_CODEPhone = "1";
103 | public static final String ERROR_CODEEmail = "2";
104 | public static final String ERROR_CODENumber = "3";
105 | public static final String ERROR_CODEFindIMEI = "5";
106 | public static final String ERROR_CODEFindUser = "4";
107 | public static final String ERROR_CODEFindOldIMEI = "6";
108 | public static final String ERROR_CODEFindPhoneUser = "7";
109 | public static final String ERROR_CODEFindCity = "8";
110 | public static final String ERROR_CODEFindPoint = "9";
111 | public static final String ERROR_CODEExitIMEI = "10";
112 | public static final String ERROR_CODEFeedback = "11";
113 | public static final String ERROR_CODEOldPhone = "12";
114 | public static final String ERROR_CODENewPhone = "13";
115 | public static final String ERROR_CODEOldEmail = "14";
116 | public static final String ERROR_CODENewEmail = "15";
117 | public static final String ERROR_CODEErrorPhone = "17";
118 | public static final String ERROR_CODEInformation= "18";
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/IdGen.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.io.Serializable;
4 | import java.security.SecureRandom;
5 | import java.util.UUID;
6 |
7 | import org.apache.shiro.session.Session;
8 | import org.apache.shiro.session.mgt.eis.SessionIdGenerator;
9 | import org.springframework.context.annotation.Lazy;
10 | import org.springframework.stereotype.Service;
11 |
12 | /**
13 | * 封装各种生成唯一性ID算法的工具类.
14 | * @author
15 | * @version 2013-01-15
16 | */
17 | @Service
18 | @Lazy(false)
19 | public class IdGen implements SessionIdGenerator {
20 |
21 | private static SecureRandom random = new SecureRandom();
22 |
23 | /**
24 | * 封装JDK自带的UUID, 通过Random数字生成, 中间无-分割.
25 | */
26 | public static String uuid() {
27 | return UUID.randomUUID().toString().replaceAll("-", "");
28 | }
29 |
30 | /**
31 | * 使用SecureRandom随机生成Long.
32 | */
33 | public static long randomLong() {
34 | return Math.abs(random.nextLong());
35 | }
36 |
37 | /**
38 | * 基于Base62编码的SecureRandom随机生成bytes.
39 | */
40 | public static String randomBase62(int length) {
41 | byte[] randomBytes = new byte[length];
42 | random.nextBytes(randomBytes);
43 | return Encodes.encodeBase62(randomBytes);
44 | }
45 |
46 |
47 | @Override
48 | public Serializable generateId(Session session) {
49 | return IdGen.uuid();
50 | }
51 |
52 | public static void main(String[] args) {
53 | System.out.println(IdGen.uuid());
54 | System.out.println(IdGen.uuid().length());
55 | // for (int i=0; i<1000; i++){
56 | // System.out.println(IdGen.randomLong() + " " + IdGen.randomBase62(5));
57 | // }
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/ImageGeo.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import com.drew.metadata.*;
4 | import com.drew.metadata.exif.*;
5 | import com.drew.imaging.jpeg.*;
6 | import com.drew.lang.*;
7 | import java.io.*;
8 |
9 | public class ImageGeo {
10 | public double lat = 0.0;
11 | public double lon = 0.0;
12 | public double alt = 0.0;
13 | public boolean error = false;
14 |
15 | public ImageGeo(String filename) {
16 | try {
17 | error = false;
18 | File jpegFile = new File(filename);
19 | Metadata metadata = JpegMetadataReader.readMetadata(jpegFile);
20 |
21 | GpsDirectory gpsdir = (GpsDirectory) metadata
22 | .getDirectory(GpsDirectory.class);
23 | Rational latpart[] = gpsdir
24 | .getRationalArray(GpsDirectory.TAG_GPS_LATITUDE);
25 | Rational lonpart[] = gpsdir
26 | .getRationalArray(GpsDirectory.TAG_GPS_LONGITUDE);
27 | String northing = gpsdir
28 | .getString(GpsDirectory.TAG_GPS_LATITUDE_REF);
29 | String easting = gpsdir
30 | .getString(GpsDirectory.TAG_GPS_LONGITUDE_REF);
31 |
32 | try {
33 | alt = gpsdir.getDouble(GpsDirectory.TAG_GPS_ALTITUDE);
34 | } catch (Exception ex) {
35 | }
36 |
37 | double latsign = 1.0d;
38 | if (northing.equalsIgnoreCase("S"))
39 | latsign = -1.0d;
40 | double lonsign = 1.0d;
41 | if (easting.equalsIgnoreCase("W"))
42 | lonsign = -1.0d;
43 | lat = (Math.abs(latpart[0].doubleValue())
44 | + latpart[1].doubleValue() / 60.0d + latpart[2]
45 | .doubleValue() / 3600.0d) * latsign;
46 | lon = (Math.abs(lonpart[0].doubleValue())
47 | + lonpart[1].doubleValue() / 60.0d + lonpart[2]
48 | .doubleValue() / 3600.0d) * lonsign;
49 |
50 | if (Double.isNaN(lat) || Double.isNaN(lon))
51 | error = true;
52 | } catch (Exception ex) {
53 | error = true;
54 | }
55 | System.out.println(filename + ": (" + lat + ", " + lon + ")");
56 | }
57 |
58 | public static void main(String[] args) {
59 | ImageGeo imageGeo = new ImageGeo(ImageGeo.class.getResource("IMAG0068.jpg").getFile());
60 | System.out.println(imageGeo.lon+","+imageGeo.lat);
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/MySerializationUtils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import org.springframework.util.SerializationUtils;
4 |
5 |
6 | public class MySerializationUtils extends SerializationUtils {
7 |
8 |
9 | /**
10 | * 将字节数组直接转成想要的对象
11 | * @param T 想转换的对象有类
12 | * @param obj 对象序列化数组
13 | * @return
14 | */
15 | @SuppressWarnings("unchecked")
16 | public static T deserialezeNative(Class T, byte[] obj) {
17 |
18 | T dp = (T) deserialize(obj);
19 |
20 | return dp;
21 | }
22 |
23 | /**
24 | * 将某对象序列化
25 | * @param obj
26 | * @return
27 | */
28 | public static byte[] serializeByteArray(Object obj) {
29 |
30 | byte[] b=serialize(obj);
31 |
32 | return b;
33 | }
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | public static void main(String []args){
42 |
43 | // ErrorCode error=new ErrorCode();
44 | // error.setChannelErrorCode("你好啊,我的对象有中的属性111111111");
45 | // byte[] b=SerializationUtils.serialize(error);
46 | //
47 | // ErrorCode nativea =MySerializationUtils.deserialezeNative(ErrorCode.class, b);
48 | // System.out.println(nativea.getChannelErrorCode());
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/MyStringBuffer.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | public class MyStringBuffer {
4 | StringBuffer sb=new StringBuffer();
5 | public MyStringBuffer append(String ...args) {
6 | for(String arg:args){
7 | sb.append(arg);
8 | }
9 | return this;
10 | }
11 | public MyStringBuffer appendH(String ...args) {
12 | for(String arg:args){
13 | sb.append(arg);
14 | }
15 | sb.append(");\n");
16 | return this;
17 | }
18 | public MyStringBuffer appendK(String ...args) {
19 | for(String arg:args){
20 | sb.append(arg);
21 | }
22 | sb.append("\n");
23 | return this;
24 | }
25 | public MyStringBuffer appendM(String ...args) {
26 | for(String arg:args){
27 | sb.append(arg);
28 | }
29 | sb.append(";\n");
30 | return this;
31 | }
32 | public boolean isEmpty(){
33 | boolean empty=false;
34 | if(StringUtils.isEmpty(sb.toString())){
35 | empty=true;
36 | }
37 | return empty;
38 | }
39 | public void insertBlankLine(){
40 | sb.append("\n");
41 | }
42 | public void printInfo(String info){
43 | sb.append("System.out.println(\""+info+"\");"+"\n");
44 | }
45 | public static String addQuote(String var){
46 | return "\""+var+"\"";
47 | }
48 | public static String addSingleQuote(String var){
49 | return "'"+var+"'";
50 | }
51 | public void clear() {
52 | sb.delete(0,sb.length());
53 | }
54 |
55 | public static final String COMMA=",";//逗号
56 | public static final String SEMICOLON=";";//分号
57 | public String toString() {
58 | return sb.toString();
59 | }
60 | public static MyStringBuffer newInstance(){
61 | return new MyStringBuffer();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/NewInstanceUtil.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.lang.reflect.InvocationTargetException;
4 | import java.math.BigDecimal;
5 | import java.util.ArrayList;
6 | import java.util.HashMap;
7 |
8 | /**
9 | * 在大量运用反射,特别是传入一个class,调用class.newInstance(),有些类比如INTGER、map等实际没有空构建器,所以会报错
10 | * 本方法进行处理
11 | *
12 | * @author liangfeng
13 | *
14 | */
15 | public class NewInstanceUtil {
16 | /**
17 | * 判断一个类型是否有空构建器
18 | * @param typeClass
19 | * @return
20 | */
21 | public static boolean ifHasNullConstructor(Class typeClass) {
22 | boolean hasinis = true;
23 | try {
24 | typeClass.getConstructor(null);// Integer等没有空参构建器,在instanceof 时调用typeClass.newInstance()会报错
25 | } catch (Exception e) {
26 | hasinis = false;
27 | }
28 | return hasinis;
29 | }
30 | /**
31 | * 注意,此方法目前创建的初衷是为了instanceof比较时使用,不能当做值类型使用,因为对于new Integer,实际是随便赋值了一个0
32 | * @param typeClass
33 | * @return
34 | */
35 | public static Object newInstance(Class typeClass){
36 | Object dest=null;
37 | if(!ifHasNullConstructor(typeClass)){//没有空构建器
38 | if(typeClass.getCanonicalName().equals("java.util.Map")){
39 | dest=new HashMap();
40 | }else if(typeClass.getCanonicalName().equals("java.lang.Integer")){
41 | dest=new Integer(0);//随便一个值,因为此方法主要是用来与 instanceof与其他类型进行比较
42 | }else if(typeClass.getCanonicalName().equals("java.lang.Double")){
43 | dest= new Double(0);//随便一个值,因为此方法主要是用来与 instanceof与其他类型进行比较
44 | }else if(typeClass.getCanonicalName().equals("java.lang.Long")){
45 | dest=new Long(0);//随便一个值,因为此方法主要是用来与 instanceof与其他类型进行比较
46 | }else if(typeClass.getCanonicalName().equals("java.lang.Short")){
47 | dest=new Short("0");//随便一个值,因为此方法主要是用来与 instanceof与其他类型进行比较
48 | }else if(typeClass.getCanonicalName().equals("java.math.BigDecimal")){
49 | dest= new BigDecimal(0);//随便一个值,因为此方法主要是用来与 instanceof与其他类型进行比较
50 | }else if(typeClass.getCanonicalName().contains("java.util.List")){
51 | dest=new ArrayList();//随便一个值,因为此方法主要是用来与 instanceof与其他类型进行比较
52 | }
53 | }else{
54 | try {
55 | dest=typeClass.newInstance();
56 | } catch (InstantiationException e) {
57 | e.printStackTrace();
58 | } catch (IllegalAccessException e) {
59 | e.printStackTrace();
60 | }
61 | }
62 | return dest;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/ObjectUtils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.ByteArrayOutputStream;
5 | import java.io.ObjectInputStream;
6 | import java.io.ObjectOutputStream;
7 | import java.lang.reflect.Method;
8 |
9 | import org.apache.commons.lang3.StringUtils;
10 |
11 | /**
12 | * 对象操作工具类, 继承org.apache.commons.lang3.ObjectUtils类
13 | * @author
14 | * @version 2014-6-29
15 | */
16 | public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
17 |
18 | /**
19 | * 注解到对象复制,只复制能匹配上的方法。
20 | * @param annotation
21 | * @param object
22 | */
23 | public static void annotationToObject(Object annotation, Object object){
24 | if (annotation != null){
25 | Class> annotationClass = annotation.getClass();
26 | Class> objectClass = object.getClass();
27 | for (Method m : objectClass.getMethods()){
28 | if (StringUtils.startsWith(m.getName(), "set")){
29 | try {
30 | String s = StringUtils.uncapitalize(StringUtils.substring(m.getName(), 3));
31 | Object obj = annotationClass.getMethod(s).invoke(annotation);
32 | if (obj != null && !"".equals(obj.toString())){
33 | if (object == null){
34 | object = objectClass.newInstance();
35 | }
36 | m.invoke(object, obj);
37 | }
38 | } catch (Exception e) {
39 | // 忽略所有设置失败方法
40 | }
41 | }
42 | }
43 | }
44 | }
45 |
46 | /**
47 | * 序列化对象
48 | * @param object
49 | * @return
50 | */
51 | public static byte[] serialize(Object object) {
52 | ObjectOutputStream oos = null;
53 | ByteArrayOutputStream baos = null;
54 | try {
55 | if (object != null){
56 | baos = new ByteArrayOutputStream();
57 | oos = new ObjectOutputStream(baos);
58 | oos.writeObject(object);
59 | return baos.toByteArray();
60 | }
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | }
64 | return null;
65 | }
66 |
67 | /**
68 | * 反序列化对象
69 | * @param bytes
70 | * @return
71 | */
72 | public static Object unserialize(byte[] bytes) {
73 | ByteArrayInputStream bais = null;
74 | try {
75 | if (bytes != null && bytes.length > 0){
76 | bais = new ByteArrayInputStream(bytes);
77 | ObjectInputStream ois = new ObjectInputStream(bais);
78 | return ois.readObject();
79 | }
80 | } catch (Exception e) {
81 | e.printStackTrace();
82 | }
83 | return null;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/PropertityUtil.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 | import java.util.HashMap;
6 | import java.util.Map;
7 | import java.util.Properties;
8 |
9 |
10 | /**描述:获取邮件配置文件中信息
11 | */
12 | public class PropertityUtil {
13 | private static HashMap map = null;
14 |
15 | /**
16 | * 方法名称: get
17 | * 描述:通过key获取资源文件中的value
18 | */
19 | public static String get(String key,String fileName){
20 | String propertyPath = fileName;
21 | if(map == null){
22 | map = new HashMap();
23 | }
24 | if(map.get(fileName) != null) {
25 | return map.get(fileName).get(key)==null?null:map.get(fileName).get(key).toString();
26 | }
27 | InputStream is = PropertityUtil.class.getClassLoader().getResourceAsStream(propertyPath);
28 | Properties propertie = new Properties();
29 | try {
30 | propertie.load(is);
31 | map.put(fileName, propertie);
32 | } catch (IOException e) {
33 | e.printStackTrace();
34 | }finally{
35 | if(is != null){
36 | try {
37 | is.close();
38 | } catch (IOException e) {
39 | e.printStackTrace();
40 | }
41 | }
42 | }
43 | return map.get(fileName).get(key)==null?null:map.get(fileName).get(key).toString();
44 | }
45 |
46 | /**
47 | * 方法名称:reload
48 | * 描述:重新加载配置文件
49 | * @param fileNames 如果为空,则reload全部配置文件
50 | */
51 | public static void reload(String... fileNames){
52 | if(fileNames.length == 0){
53 | fileNames = map.keySet().toArray(new String[0]);
54 | }
55 | String propertyPath;
56 | for (String fileName : fileNames) {
57 | propertyPath = fileName;
58 | if(map == null){
59 | map = new HashMap();
60 | }
61 | map.remove(fileName);
62 | InputStream is = PropertityUtil.class.getClassLoader().getResourceAsStream(propertyPath);
63 | Properties propertie = new Properties();
64 | try {
65 | propertie.load(is);
66 | map.put(fileName, propertie);
67 | } catch (IOException e) {
68 | e.printStackTrace();
69 | }finally{
70 | if(is != null){
71 | try {
72 | is.close();
73 | } catch (IOException e) {
74 | e.printStackTrace();
75 | }
76 | }
77 | }
78 | }
79 | }
80 |
81 |
82 | public static Map getMap(String fileName){
83 | String propertyPath = fileName;
84 | if(map == null){
85 | map = new HashMap();
86 | }
87 | if(map.get(fileName) != null) {
88 | return new HashMap((Map) map.get(fileName));
89 | }
90 | InputStream is = PropertityUtil.class.getClassLoader().getResourceAsStream(propertyPath);
91 | Properties propertie = new Properties();
92 | try {
93 | propertie.load(is);
94 | map.put(fileName, propertie);
95 | } catch (IOException e) {
96 | e.printStackTrace();
97 | }finally{
98 | if(is != null){
99 | try {
100 | is.close();
101 | } catch (IOException e) {
102 | e.printStackTrace();
103 | }
104 | }
105 | }
106 | return new HashMap((Map) map.get(fileName));
107 |
108 | }
109 | }
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/QrCodeUtil.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 | import java.awt.Color;
3 | import java.awt.Graphics2D;
4 | import java.awt.Image;
5 | import java.awt.image.BufferedImage;
6 | import java.io.ByteArrayOutputStream;
7 | import java.io.File;
8 | import javax.imageio.ImageIO;
9 |
10 | import com.swetake.util.Qrcode;
11 |
12 | /**
13 | * 生成二维码工具
14 | *
15 | */
16 | public class QrCodeUtil {
17 |
18 | public static void main(String[] args) {
19 | byte[] bb = createQRCode("www.baidu.com", null);
20 | System.out.println(bb);
21 | }
22 | /**
23 | * @Description: 生成二维码
24 | * @param:qrUrl二维码url
25 | * @param:logoUrl
26 | * @author: lijiafu
27 | * @since: 2016年3月2日 下午6:25:15
28 | */
29 | public static byte[] createQRCode(String qrUrl,String logo) {
30 | byte[] data = null;
31 | try {
32 | Qrcode qrcodeHandler = new Qrcode();
33 | qrcodeHandler.setQrcodeErrorCorrect('M');
34 | qrcodeHandler.setQrcodeEncodeMode('B');
35 | qrcodeHandler.setQrcodeVersion(7);
36 | byte[] contentBytes = qrUrl.getBytes("gb2312");
37 | // 构造一个BufferedImage对象 设置宽、高
38 | BufferedImage bufImg = new BufferedImage(140, 140,
39 | BufferedImage.TYPE_INT_RGB);
40 | Graphics2D gs = bufImg.createGraphics();
41 | gs.setBackground(Color.white);
42 | gs.clearRect(0, 0, 140, 140);
43 | // 设定图像颜色 > BLACK
44 | gs.setColor(Color.BLACK);
45 | // 设置偏移量 不设置可能导致解析出错
46 | int pixoff = 2;
47 | // 输出内容 > 二维码
48 | if (contentBytes.length > 0 && contentBytes.length < 120) {
49 | boolean[][] codeOut = qrcodeHandler.calQrcode(contentBytes);
50 | for (int i = 0; i < codeOut.length; i++) {
51 | for (int j = 0; j < codeOut.length; j++) {
52 | if (codeOut[j][i]) {
53 | gs.fillRect(j * 3 + pixoff, i * 3 + pixoff, 3, 3);
54 | }
55 | }
56 | }
57 |
58 | } else {
59 | System.err.println("QRCode content bytes length = "
60 | + contentBytes.length + " not in [ 0,120 ]. ");
61 | return null;
62 | }
63 | if(logo !=null){
64 | Image img = ImageIO.read(new File(logo));// 实例化一个Image对象。
65 | gs.drawImage(img, 55, 55, 30, 30, null);//logo位置
66 | }
67 |
68 | gs.dispose();
69 | bufImg.flush();
70 | // 生成二维码QRCode图片
71 | ByteArrayOutputStream bsout = new ByteArrayOutputStream();
72 | ImageIO.write(bufImg, "png", bsout);
73 | data = bsout.toByteArray();
74 | // ImageIO.write(bufImg, "png", imgFile);
75 | } catch (Exception e) {
76 | e.printStackTrace();
77 | return null;
78 | }
79 | return data;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/SqlUtils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import com.fasterxml.jackson.databind.deser.Deserializers.Base;
4 | import com.tengjie.common.persistence.TjBaseEntity;
5 |
6 | /**
7 | * sql的一些工具类
8 | * @author admin
9 | *
10 | */
11 | public class SqlUtils {
12 | /**
13 | * 获得年格式化sql
14 | * @param fieldName
15 | */
16 | public static String findYearFormatSql(String fieldName) {
17 | fieldName=StringUtils.toUnderScoreCase(fieldName);
18 | String sql=" DATE_FORMAT("+fieldName+",'%Y') ";
19 | return sql;
20 | }
21 | /**
22 | * 获得季格式化sql
23 | * @param fieldName
24 | */
25 | public static String findQuarterFormatSql(String fieldName) {
26 | fieldName=StringUtils.toUnderScoreCase(fieldName);
27 | String sql=" concat(date_format("+fieldName+", '%Y'),FLOOR((date_format("+fieldName+", '%m')+2)/3)) ";
28 | return sql;
29 | }
30 | /**
31 | * 获得月格式化sql
32 | * @param fieldName
33 | */
34 | public static String findMonthFormatSql(String fieldName) {
35 | fieldName=StringUtils.toUnderScoreCase(fieldName);
36 | String sql=" DATE_FORMAT("+fieldName+",'%Y-%m') ";
37 | return sql;
38 | }
39 |
40 | /**
41 | * 构建调用递归树查询函数的select sql语句,首先需要在数据库构建好函数,这里只是调用而已。
42 | * 注意:会把拼接好的sql方到anySql中
43 | * @param functionName:要调用的函数名
44 | * @param entity:实体,实体中可以包含了与其他表关联的其他语句,依然遵循原来的规则
45 | * @param paramValue:传入函数的参数值
46 | * @param ifContianInObj:返回的列表中是否包含传入参数对应的值,true包含,false不包含
47 | * @return
48 | */
49 | public static void buildMysqlTreeFunctionSelectSql(String functionName,TjBaseEntity entity,String paramValue,boolean ifContianInObj) {
50 |
51 | String anySql="select a.* from tb_comment_record a where FIND_IN_SET(a.id, find_comment_record_tree_function("+paramValue+")) ";
52 | entity.setAnySql(anySql);
53 | entity.putOrderBy(" find_in_set(a.id, find_comment_record_tree_function("+paramValue+"))", "asc");
54 | if(!ifContianInObj) {
55 | entity.appendWhereCondSql(" a.id !="+paramValue);
56 | }
57 | }
58 | /**
59 | * 创建数据结构的存储过程代码,注意:直接创建函数会出现This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary
60 | mysql的设置默认是不允许创建函数
61 | ∂解决办法1:
62 | 执行:
63 | SET GLOBAL log_bin_trust_function_creators = 1;
64 | 不过 重启了 就失效了
65 | 注意: 有主从复制的时候 从机必须要设置 不然会导致主从同步失败
66 | 解决办法2:
67 | 在my.cnf里面设置
68 | log-bin-trust-function-creators=1
69 | 不过这个需要重启服务
70 | 调用函数:select find_comment_record_tree_function(1)); 1为id
71 | select * from tb_comment_record where FIND_IN_SET(id, find_comment_record_tree_function(9)) order by FIND_IN_SET(id, find_comment_record_tree_function(9))
72 | */
73 | // DROP FUNCTION IF EXISTS find_comment_record_tree_function;
74 | // CREATE FUNCTION `find_comment_record_tree_function` (rootId VARCHAR(32)<备注:如果是varchar必须跟后面的位数>) RETURNS VARCHAR(4000)
75 | // BEGIN
76 | // DECLARE sTemp VARCHAR(4000);
77 | // DECLARE sTempChd VARCHAR(4000);
78 | //
79 | // SET sTemp = '$';
80 | // SET sTempChd =cast(rootId as CHAR);
81 | //
82 | // WHILE sTempChd is not null DO
83 | // SET sTemp = concat(sTemp,',',sTempChd);
84 | // SELECT group_concat(id) INTO sTempChd FROM tb_comment_record where FIND_IN_SET(parent_id,sTempChd)>0;
85 | // END WHILE;
86 | // RETURN sTemp;
87 | // END ;
88 | }
89 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/SystemPath.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | /**
4 | * @author
5 | * @date Dec 14, 2008
6 | * @version v 1.0
7 | * @description 得到当前应用的系统路径
8 | */
9 | public class SystemPath {
10 |
11 | public static String getSysPath() {
12 | String path = Thread.currentThread().getContextClassLoader()
13 | .getResource("").toString();
14 | String temp = path.replaceFirst("file:/", "").replaceFirst(
15 | "WEB-INF/classes/", "");
16 | String separator = System.getProperty("file.separator");
17 | String resultPath = temp.replaceAll("/", separator + separator);
18 | return resultPath;
19 | }
20 |
21 | public static String getClassPath() {
22 | String path = Thread.currentThread().getContextClassLoader()
23 | .getResource("").toString();
24 | String temp = path.replaceFirst("file:/", "");
25 | String separator = System.getProperty("file.separator");
26 | String resultPath = temp.replaceAll("/", separator + separator);
27 | return resultPath;
28 | }
29 |
30 | public static String getSystempPath() {
31 | return System.getProperty("java.io.tmpdir");
32 | }
33 |
34 | public static String getSeparator() {
35 | return System.getProperty("file.separator");
36 | }
37 |
38 | public static void main(String[] args) {
39 | System.out.println(getSysPath());
40 | System.out.println(System.getProperty("java.io.tmpdir"));
41 | System.out.println(getSeparator());
42 | System.out.println(getClassPath());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/Threads.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.util.concurrent.ExecutorService;
4 | import java.util.concurrent.TimeUnit;
5 |
6 | /**
7 | * 线程相关工具类.
8 | * @author
9 | * @version 2013-01-15
10 | */
11 | public class Threads {
12 |
13 | /**
14 | * sleep等待,单位为毫秒,忽略InterruptedException.
15 | */
16 | public static void sleep(long millis) {
17 | try {
18 | Thread.sleep(millis);
19 | } catch (InterruptedException e) {
20 | // Ignore.
21 | return;
22 | }
23 | }
24 |
25 | /**
26 | * sleep等待,忽略InterruptedException.
27 | */
28 | public static void sleep(long duration, TimeUnit unit) {
29 | try {
30 | Thread.sleep(unit.toMillis(duration));
31 | } catch (InterruptedException e) {
32 | // Ignore.
33 | return;
34 | }
35 | }
36 |
37 | /**
38 | * 按照ExecutorService JavaDoc示例代码编写的Graceful Shutdown方法.
39 | * 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务.
40 | * 如果超时, 则调用shutdownNow, 取消在workQueue中Pending的任务,并中断所有阻塞函数.
41 | * 如果仍人超時,則強制退出.
42 | * 另对在shutdown时线程本身被调用中断做了处理.
43 | */
44 | public static void gracefulShutdown(ExecutorService pool, int shutdownTimeout, int shutdownNowTimeout,
45 | TimeUnit timeUnit) {
46 | pool.shutdown(); // Disable new tasks from being submitted
47 | try {
48 | // Wait a while for existing tasks to terminate
49 | if (!pool.awaitTermination(shutdownTimeout, timeUnit)) {
50 | pool.shutdownNow(); // Cancel currently executing tasks
51 | // Wait a while for tasks to respond to being cancelled
52 | if (!pool.awaitTermination(shutdownNowTimeout, timeUnit)) {
53 | System.err.println("Pool did not terminated");
54 | }
55 | }
56 | } catch (InterruptedException ie) {
57 | // (Re-)Cancel if current thread also interrupted
58 | pool.shutdownNow();
59 | // Preserve interrupt status
60 | Thread.currentThread().interrupt();
61 | }
62 | }
63 |
64 | /**
65 | * 直接调用shutdownNow的方法, 有timeout控制.取消在workQueue中Pending的任务,并中断所有阻塞函数.
66 | */
67 | public static void normalShutdown(ExecutorService pool, int timeout, TimeUnit timeUnit) {
68 | try {
69 | pool.shutdownNow();
70 | if (!pool.awaitTermination(timeout, timeUnit)) {
71 | System.err.println("Pool did not terminated");
72 | }
73 | } catch (InterruptedException ie) {
74 | Thread.currentThread().interrupt();
75 | }
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/ThreeDES.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 |
4 | import javax.crypto.Cipher;
5 | import javax.crypto.SecretKey;
6 | import javax.crypto.spec.SecretKeySpec;
7 |
8 | import com.tengjie.common.config.Global;
9 |
10 | /**
11 | * 3DES加密
12 | *
13 | */
14 | public class ThreeDES {
15 |
16 | private static final String Algorithm = "DESede"; // 定义 加密算法,可用DES,DESede,Blowfish
17 |
18 |
19 | // 加密入口,外部调用此方法
20 | public static String encryptMode(String pass, String str) {
21 | try {
22 | byte[] resultByte = encryptMode(pass.getBytes(), str.getBytes());
23 | // 为了防止解密时报javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher异常,
24 | // 不能把加密后的字节数组直接转换成字符串
25 | return Base64Utils.encode(resultByte);
26 | } catch (Exception e) {
27 | e.printStackTrace();
28 | }
29 | return null;
30 | }
31 |
32 | // 解密入口,外部调用此方法
33 | public static String decryptMode(String pass, String str) {
34 | try {
35 | byte[] resultByte = decryptMode(pass.getBytes(), Base64Utils.decode(str.toCharArray()));
36 | return new String(resultByte,"UTF-8");
37 | } catch (Exception e) {
38 | e.printStackTrace();
39 | }
40 | return null;
41 | }
42 |
43 | /**
44 | * 加密方法
45 | *
46 | * @param keybyte
47 | * 加密密钥,长度为24字节
48 | * @param src
49 | * 被加密的数据缓冲区(源)
50 | * @return
51 | * @author SHANHY
52 | * @date 2015-8-18
53 | */
54 | public static byte[] encryptMode(byte[] keybyte, byte[] src) {
55 | try {
56 | // 生成密钥
57 | SecretKey deskey = new SecretKeySpec(keybyte, Algorithm);
58 |
59 | // 加密
60 | Cipher c1 = Cipher.getInstance(Algorithm);
61 | c1.init(Cipher.ENCRYPT_MODE, deskey);
62 | return c1.doFinal(src);
63 | } catch (java.security.NoSuchAlgorithmException e1) {
64 | e1.printStackTrace();
65 | } catch (javax.crypto.NoSuchPaddingException e2) {
66 | e2.printStackTrace();
67 | } catch (java.lang.Exception e3) {
68 | e3.printStackTrace();
69 | }
70 | return null;
71 | }
72 |
73 | /**
74 | * 解密
75 | *
76 | * @param keybyte
77 | * 加密密钥,长度为24字节
78 | * @param src
79 | * 加密后的缓冲区
80 | * @return
81 | * @author SHANHY
82 | * @date 2015-8-18
83 | */
84 | public static byte[] decryptMode(byte[] keybyte, byte[] src) {
85 | try {
86 | // 生成密钥
87 | SecretKey deskey = new SecretKeySpec(keybyte, Algorithm);
88 |
89 | // 解密
90 | Cipher c1 = Cipher.getInstance(Algorithm);
91 | c1.init(Cipher.DECRYPT_MODE, deskey);
92 | return c1.doFinal(src);
93 | } catch (java.security.NoSuchAlgorithmException e1) {
94 | e1.printStackTrace();
95 | } catch (javax.crypto.NoSuchPaddingException e2) {
96 | e2.printStackTrace();
97 | } catch (java.lang.Exception e3) {
98 | e3.printStackTrace();
99 | }
100 | return null;
101 | }
102 |
103 | /**
104 | * 转换成十六进制字符串
105 | *
106 | * @param b
107 | * @return
108 | * @author SHANHY
109 | * @date 2015-8-18
110 | */
111 | public static String byte2hex(byte[] b) {
112 | String hs = "";
113 | String stmp = "";
114 |
115 | for (int n = 0; n < b.length; n++) {
116 | stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
117 | if (stmp.length() == 1)
118 | hs = hs + "0" + stmp;
119 | else
120 | hs = hs + stmp;
121 | if (n < b.length - 1)
122 | hs = hs + ":";
123 | }
124 | return hs.toUpperCase();
125 | }
126 |
127 | /**
128 | * 测试以及调用
129 | * @Description: TODO
130 | * @author: 高泽
131 | * @since: 2017年8月30日 下午5:36:14
132 | */
133 | public static void main(String[] args) {
134 |
135 | String secret = "33WJ9AGXogm2TOiMKy^LREg*";// Global.getConfig("trdDesKey");
136 | String szSrc2 = "1005036";
137 | String result = encryptMode(secret, szSrc2);
138 | System.out.println("加密后的结果:"+result);
139 | String result2 = decryptMode(secret, result);
140 | System.out.println("解密后的结果:"+result2);
141 | }
142 | }
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/TjLinkedMap.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.io.Serializable;
4 | import java.text.ParseException;
5 | import java.util.ArrayList;
6 | import java.util.HashMap;
7 | import java.util.LinkedHashMap;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.Set;
11 | /**
12 | * 为创建动态属性和mapper中处理运算符时专用map
13 | * @author liangfeng
14 | *
15 | * @param
16 | * @param
17 | */
18 | public class TjLinkedMap extends LinkedHashMap implements Serializable {
19 | private static final long serialVersionUID = 1L;
20 | /**
21 | * 通用添加方法
22 | * @param key
23 | * @param value
24 | * @return 返回当前map对象
25 | */
26 | public TjLinkedMap putCon(K key, V value) {
27 | super.put(key, value);
28 | return this;
29 | }
30 | /**
31 | * 通用添加方法
32 | * @param key
33 | * @param value
34 | * @return 返回当前map对象
35 | */
36 | public TjLinkedMap putCon(K ...keys) {
37 | for(K key:keys){
38 | super.put(key, (V) key);
39 | }
40 | return this;
41 | }
42 | /**
43 | * 本方法为动态添加属性时使用,key为属性名,value自动为String.class
44 | * @param key 属性名
45 | * @return
46 | */
47 | public TjLinkedMap put(K key) {
48 | super.put(key, (V) java.lang.String.class);
49 | return this;
50 | }
51 | /**
52 | * 本方法为动态添加属性时使用,key为属性名,value自动为String.class
53 | * @param key 属性名
54 | * @return
55 | */
56 | public TjLinkedMap removeCon(K ...key) {
57 | for(K t:key){
58 | super.remove(t);
59 | }
60 | return this;
61 | }
62 | /**
63 | * 为mapper中处理运算符时使用,若get不到,默认返回=
64 | */
65 | public V get(Object key) {
66 | V value=null;
67 | value=super.get(key);
68 | // if(value==null||StringUtils.isEmpty(value+"")){
69 | // value=(V) "=";
70 | // }
71 | //
72 | return value;
73 |
74 | }
75 | /**
76 | * 根据目标类型clazz获得对应的值
77 | * @param
78 | * @param key
79 | * @param clazz
80 | * @param defaultValue:为空时返回的默认值
81 | * @return
82 | */
83 | public T getValue(String key,Class clazz){
84 | return getValue(key,clazz,null);
85 | }
86 | /**
87 | * 根据目标类型clazz获得对应的值
88 | * @param
89 | * @param key
90 | * @param clazz
91 | * @param defaultValue:为空时返回的默认值
92 | * @return
93 | */
94 | public T getValue(String key,Class clazz,Object defaultValue){
95 | T result=null;
96 | Object obj=super.get(key);
97 | if(obj!=null) {
98 | try {
99 | return MyBeanUtils.getDestTypeValue(obj, clazz);
100 | } catch (ParseException e) {
101 | e.printStackTrace();
102 | }
103 | }else {
104 | if(defaultValue!=null) {
105 | result=(T) defaultValue;
106 | }
107 |
108 | }
109 | return result;
110 | }
111 | public static TjLinkedMap newInstance(){
112 | return new TjLinkedMap();
113 | }
114 | /**
115 | * 模糊匹配key值,只要包含就行
116 | */
117 | public List getLike(K key) {
118 | List list = null;
119 | list = new ArrayList();
120 | K[] a = null;
121 | Set set = this.keySet();
122 | a = (K[])set.toArray();
123 | for (int i = 0; i < a.length; i++) {
124 | if (a[i].toString().indexOf(key.toString()) == -1) {
125 | continue;
126 | } else {
127 | list.add(this.get(a[i]));
128 | }
129 | }
130 | return list;
131 |
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/TjList.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.io.Serializable;
4 | import java.util.ArrayList;
5 |
6 | public class TjList extends ArrayList implements Serializable {
7 | private static final long serialVersionUID = 1L;
8 | public boolean add(E ...args) {
9 | for (int i = 0; i < args.length; i++) {
10 | super.add(args[i]);
11 | }
12 | return true;
13 | }
14 | public TjList addCon(E args) {
15 |
16 | super.add(args);
17 |
18 | return this;
19 | }
20 |
21 | public static TjList newInstance(){
22 | return new TjList();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/TjMap.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 | /**
3 | * tjMap的get方法有问题,如果遇到为空则放回=,但是不能动,因为在mapper处理中要使用,因此通用的用这个TjNewmap,tjMap不再维护
4 | */
5 | import java.io.Serializable;
6 | import java.util.ArrayList;
7 | import java.util.HashMap;
8 | import java.util.List;
9 | import java.util.Set;
10 | /**
11 | * 为创建动态属性和mapper中处理运算符时专用map
12 | * @author liangfeng
13 | *
14 | * @param
15 | * @param
16 | */
17 | public class TjMap extends HashMap implements Serializable {
18 | private static final long serialVersionUID = 1L;
19 | /**
20 | * 通用添加方法
21 | * @param key
22 | * @param value
23 | * @return 返回当前map对象
24 | */
25 | public TjMap putCon(K key, V value) {
26 | super.put(key, value);
27 | return this;
28 | }
29 | /**
30 | * 添加el表达式形式的value,会自动对value进行添加${}
31 | * @param key
32 | * @param value
33 | * @return 返回当前map对象
34 | */
35 | public TjMap putConEl(String key, String value) {
36 | super.put((K)key, (V)("${"+value+"}"));
37 | return this;
38 | }
39 |
40 | /**
41 | * 通用添加方法
42 | * @param key
43 | * @param value
44 | * @return 返回当前map对象
45 | */
46 | public TjMap putCon(K ...keys) {
47 | for(K key:keys){
48 | super.put(key, (V) key);
49 | }
50 | return this;
51 | }
52 | /**
53 | * 本方法为动态添加属性时使用,key为属性名,value自动为String.class
54 | * @param key 属性名
55 | * @return
56 | */
57 | public TjMap put(K key) {
58 | super.put(key, (V) java.lang.String.class);
59 | return this;
60 | }
61 | /**
62 | * 本方法为动态添加属性时使用,key为属性名,value自动为String.class
63 | * @param key 属性名
64 | * @return
65 | */
66 | public TjMap removeCon(K ...key) {
67 | for(K t:key){
68 | super.remove(t);
69 | }
70 | return this;
71 | }
72 | /**
73 | * 为mapper中处理运算符时使用,若get不到,默认返回=
74 | */
75 | public V get(Object key) {
76 | V value=null;
77 | value=super.get(key);
78 | if(value==null||StringUtils.isEmpty(value+"")){
79 | value=(V) "=";
80 | }
81 |
82 | return value;
83 |
84 | }
85 | /**
86 | * 为mapper中处理运算符时使用,若get不到,默认返回=
87 | */
88 | public V get(Object key,V defaultValue) {
89 | V value=null;
90 | value=super.get(key);
91 | if(value==null||StringUtils.isEmpty(value+"")){
92 | value=(V) "=";
93 | }
94 |
95 | return value;
96 |
97 | }
98 | /**
99 | * 模糊匹配key值,只要包含就行
100 | */
101 | public List getLike(K key) {
102 | List list = null;
103 | list = new ArrayList();
104 | K[] a = null;
105 | Set set = this.keySet();
106 | a = (K[])set.toArray();
107 | for (int i = 0; i < a.length; i++) {
108 | if (a[i].toString().indexOf(key.toString()) == -1) {
109 | continue;
110 | } else {
111 | list.add(this.get(a[i]));
112 | }
113 | }
114 | return list;
115 |
116 | }
117 | public static TjMap newInstance(){
118 | return new TjMap();
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/UserAgentUtils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import javax.servlet.http.HttpServletRequest;
4 |
5 | import eu.bitwalker.useragentutils.Browser;
6 | import eu.bitwalker.useragentutils.DeviceType;
7 | import eu.bitwalker.useragentutils.UserAgent;
8 |
9 | /**
10 | * 用户代理字符串识别工具
11 | * @author
12 | * @version 2014-6-13
13 | */
14 | public class UserAgentUtils {
15 |
16 | /**
17 | * 获取用户代理对象
18 | * @param request
19 | * @return
20 | */
21 | public static UserAgent getUserAgent(HttpServletRequest request){
22 | return UserAgent.parseUserAgentString(request.getHeader("User-Agent"));
23 | }
24 |
25 | /**
26 | * 获取设备类型
27 | * @param request
28 | * @return
29 | */
30 | public static DeviceType getDeviceType(HttpServletRequest request){
31 | return getUserAgent(request).getOperatingSystem().getDeviceType();
32 | }
33 |
34 | /**
35 | * 是否是PC
36 | * @param request
37 | * @return
38 | */
39 | public static boolean isComputer(HttpServletRequest request){
40 | return DeviceType.COMPUTER.equals(getDeviceType(request));
41 | }
42 |
43 | /**
44 | * 是否是手机
45 | * @param request
46 | * @return
47 | */
48 | public static boolean isMobile(HttpServletRequest request){
49 | return DeviceType.MOBILE.equals(getDeviceType(request));
50 | }
51 |
52 | /**
53 | * 是否是平板
54 | * @param request
55 | * @return
56 | */
57 | public static boolean isTablet(HttpServletRequest request){
58 | return DeviceType.TABLET.equals(getDeviceType(request));
59 | }
60 |
61 | /**
62 | * 是否是手机和平板
63 | * @param request
64 | * @return
65 | */
66 | public static boolean isMobileOrTablet(HttpServletRequest request){
67 | DeviceType deviceType = getDeviceType(request);
68 | return DeviceType.MOBILE.equals(deviceType) || DeviceType.TABLET.equals(deviceType);
69 | }
70 |
71 | /**
72 | * 获取浏览类型
73 | * @param request
74 | * @return
75 | */
76 | public static Browser getBrowser(HttpServletRequest request){
77 | return getUserAgent(request).getBrowser();
78 | }
79 |
80 | /**
81 | * 是否IE版本是否小于等于IE8
82 | * @param request
83 | * @return
84 | */
85 | public static boolean isLteIE8(HttpServletRequest request){
86 | Browser browser = getBrowser(request);
87 | return Browser.IE5.equals(browser) || Browser.IE6.equals(browser)
88 | || Browser.IE7.equals(browser) || Browser.IE8.equals(browser);
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/java/com/tengjie/common/utils/WorkDayUtils.java:
--------------------------------------------------------------------------------
1 | package com.tengjie.common.utils;
2 |
3 | import java.text.SimpleDateFormat;
4 | import java.util.Calendar;
5 | import java.util.Date;
6 |
7 | public class WorkDayUtils {
8 |
9 | public static void main(String[] args) {
10 | try {
11 | String strDateStart = "2013-08-01";
12 | String strDateEnd = "2014-08-31";
13 |
14 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
15 | Date date_start = sdf.parse(strDateStart);
16 | Date date_end = sdf.parse(strDateEnd);
17 | WorkDayUtils app = new WorkDayUtils();
18 | Calendar cal_start = Calendar.getInstance();
19 | Calendar cal_end = Calendar.getInstance();
20 | cal_start.setTime(date_start);
21 | cal_end.setTime(date_end);
22 | System.out.println("开始日:" + cal_start.get(Calendar.YEAR) + "-" + (cal_start.get(Calendar.MONTH) + 1)
23 | + "-" + cal_start.get(Calendar.DAY_OF_MONTH) + " " + app.getChineseWeek(cal_start));
24 | System.out.println("结束日:" + cal_end.get(Calendar.YEAR) + "-" + (cal_end.get(Calendar.MONTH) + 1)
25 | + "-" + cal_end.get(Calendar.DAY_OF_MONTH) + " " + app.getChineseWeek(cal_end));
26 | System.out.println("工作日:" + app.getWorkingDay(cal_start, cal_end));
27 | System.out.println("休息日:" + app.getHolidays(cal_start, cal_end));
28 | } catch (Exception e) {
29 | e.printStackTrace();
30 | }
31 | }
32 |
33 | /**
34 | * 获取日期之间的天数
35 | * @param d1
36 | * @param d2
37 | * @return
38 | */
39 | public int getDaysBetween(Calendar d1, Calendar d2) {
40 | if (d1.after(d2)) { // swap dates so that d1 is start and d2 is end
41 | Calendar swap = d1;
42 | d1 = d2;
43 | d2 = swap;
44 | }
45 | int days = d2.get(Calendar.DAY_OF_YEAR)
46 | - d1.get(Calendar.DAY_OF_YEAR);
47 | int y2 = d2.get(Calendar.YEAR);
48 | if (d1.get(Calendar.YEAR) != y2) {
49 | d1 = (Calendar) d1.clone();
50 | do {
51 | days += d1.getActualMaximum(Calendar.DAY_OF_YEAR);
52 | d1.add(Calendar.YEAR, 1);
53 | } while (d1.get(Calendar.YEAR) != y2);
54 | }
55 | return days;
56 | }
57 |
58 | /**
59 | * 获取工作日
60 | * @param d1
61 | * @param d2
62 | * @return
63 | */
64 | public int getWorkingDay(Calendar d1, Calendar d2) {
65 | int result = -1;
66 | if (d1.after(d2)) { // swap dates so that d1 is start and d2 is end
67 | Calendar swap = d1;
68 | d1 = d2;
69 | d2 = swap;
70 | }
71 | // int betweendays = getDaysBetween(d1, d2);
72 | // int charge_date = 0;
73 | int charge_start_date = 0;// 开始日期的日期偏移量
74 | int charge_end_date = 0;// 结束日期的日期偏移量
75 | // 日期不在同一个日期内
76 | int stmp;
77 | int etmp;
78 | stmp = 7 - d1.get(Calendar.DAY_OF_WEEK);
79 | etmp = 7 - d2.get(Calendar.DAY_OF_WEEK);
80 | if (stmp != 0 && stmp != 6) {// 开始日期为星期六和星期日时偏移量为0
81 | charge_start_date = stmp - 1;
82 | }
83 | if (etmp != 0 && etmp != 6) {// 结束日期为星期六和星期日时偏移量为0
84 | charge_end_date = etmp - 1;
85 | }
86 | // }
87 | result = (getDaysBetween(this.getNextMonday(d1), this.getNextMonday(d2)) / 7)
88 | * 5 + charge_start_date - charge_end_date;
89 | // System.out.println("charge_start_date>" + charge_start_date);
90 | // System.out.println("charge_end_date>" + charge_end_date);
91 | // System.out.println("between day is-->" + betweendays);
92 | return result;
93 | }
94 |
95 | /**
96 | * 获取中文日期
97 | * @param date
98 | * @return
99 | */
100 | public String getChineseWeek(Calendar date) {
101 | final String dayNames[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
102 | int dayOfWeek = date.get(Calendar.DAY_OF_WEEK);
103 | // System.out.println(dayNames[dayOfWeek - 1]);
104 | return dayNames[dayOfWeek - 1];
105 | }
106 |
107 | /**
108 | * 获得日期的下一个星期一的日期
109 | * @param date
110 | * @return
111 | */
112 | public Calendar getNextMonday(Calendar date) {
113 | Calendar result = null;
114 | result = date;
115 | do {
116 | result = (Calendar) result.clone();
117 | result.add(Calendar.DATE, 1);
118 | } while (result.get(Calendar.DAY_OF_WEEK) != 2);
119 | return result;
120 | }
121 |
122 | /**
123 | * 获取休息日
124 | * @param d1
125 | * @param d2
126 | * @return
127 | */
128 | public int getHolidays(Calendar d1, Calendar d2) {
129 | return this.getDaysBetween(d1, d2) - this.getWorkingDay(d1, d2);
130 | }
131 |
132 | }
133 |
--------------------------------------------------------------------------------
/tengjie-base/src/main/webapp/allatori-annotations.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/webapp/allatori-annotations.jar
--------------------------------------------------------------------------------
/tengjie-base/src/main/webapp/allatori.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/webapp/allatori.jar
--------------------------------------------------------------------------------
/tengjie-base/src/main/webapp/apache-ant-zip-2.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/webapp/apache-ant-zip-2.3.jar
--------------------------------------------------------------------------------
/tengjie-base/src/main/webapp/catalina.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/webapp/catalina.jar
--------------------------------------------------------------------------------
/tengjie-base/src/main/webapp/cglib-3.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/webapp/cglib-3.1.jar
--------------------------------------------------------------------------------
/tengjie-base/src/main/webapp/ckfinder-2.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/webapp/ckfinder-2.3.jar
--------------------------------------------------------------------------------
/tengjie-base/src/main/webapp/javassist.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/webapp/javassist.jar
--------------------------------------------------------------------------------
/tengjie-base/src/main/webapp/pinyin4j-2.5.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/webapp/pinyin4j-2.5.0.jar
--------------------------------------------------------------------------------
/tengjie-base/src/main/webapp/tomcat-coyote.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kevinliang-123/mybatis-topspeed/9fd0dd66ef6b906824768f4386c53b3e4b1975e5/tengjie-base/src/main/webapp/tomcat-coyote.jar
--------------------------------------------------------------------------------