Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
ZhangKuan
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张宽
ZhangKuan
Commits
1b7a89e9
Commit
1b7a89e9
authored
Aug 02, 2017
by
胡小根
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of 115.28.80.125:templates/springmvcprojecttemplate
parents
73ba31e7
aed50eb7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
129 additions
and
18 deletions
+129
-18
clean_mybatis_generated_springmvc.sh
clean_mybatis_generated_springmvc.sh
+1
-0
pom.xml
pom.xml
+20
-12
MybatisExampleHelper.java
...eekTruthBackend/service/HmUtils/MybatisExampleHelper.java
+102
-0
mysqlGeneratorConfig.xml
web/src/main/resources/mybatis/mysqlGeneratorConfig.xml
+2
-2
oracleGeneratorConfig.xml
web/src/main/resources/mybatis/oracleGeneratorConfig.xml
+4
-4
No files found.
clean_mybatis_generated_springmvc.sh
View file @
1b7a89e9
#!/bin/bash
#!/bin/bash
rm
-rf
dao/src/main/java/com/haomostudio/SpringMVCProjectTemplate/dao/
*
rm
-rf
dao/src/main/java/com/haomostudio/SpringMVCProjectTemplate/dao/
*
rm
-rf
domain/src/main/java/com/haomostudio/SpringMVCProjectTemplate/domain/
*
rm
-rf
domain/src/main/java/com/haomostudio/SpringMVCProjectTemplate/domain/
*
...
...
pom.xml
View file @
1b7a89e9
...
@@ -160,19 +160,21 @@
...
@@ -160,19 +160,21 @@
</dependency>
</dependency>
<!-- 添加oracle jdbc driver -->
<!-- 添加oracle jdbc driver -->
<dependency>
<groupId>
com.oracle
</groupId>
<artifactId>
ojdbc6
</artifactId>
<version>
11.2.0.1.0
</version>
</dependency>
<!-- 添加mysql jdbc driver -->
<!--<dependency>-->
<!--<dependency>-->
<!--<groupId>
mysql
</groupId>-->
<!--<groupId>
com.oracle
</groupId>-->
<!--<artifactId>
mysql-connector-java
</artifactId>-->
<!--<artifactId>
ojdbc6
</artifactId>-->
<!--<version>
5.1.38
</version>-->
<!--<version>
11.2.0.1.0
</version>-->
<!--</dependency>-->
<!--</dependency>-->
<!-- 添加mysql jdbc driver -->
<dependency>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<version>
5.1.38
</version>
</dependency>
<!--<dependency>-->
<!--<dependency>-->
<!--<groupId>postgresql</groupId>-->
<!--<groupId>postgresql</groupId>-->
<!--<artifactId>postgresql</artifactId>-->
<!--<artifactId>postgresql</artifactId>-->
...
@@ -340,6 +342,12 @@
...
@@ -340,6 +342,12 @@
<version>
${poi.version}
</version>
<version>
${poi.version}
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.mybatis.generator
</groupId>
<artifactId>
mybatis-generator-maven-plugin
</artifactId>
<version>
1.3.5
</version>
</dependency>
<dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<artifactId>
httpclient
</artifactId>
...
@@ -521,8 +529,8 @@
...
@@ -521,8 +529,8 @@
<artifactId>
mybatis-generator-maven-plugin
</artifactId>
<artifactId>
mybatis-generator-maven-plugin
</artifactId>
<version>
1.3.5
</version>
<version>
1.3.5
</version>
<configuration>
<configuration>
<
!--<configurationFile>${basedir}/src/main/resources/mybatis/mysqlGeneratorConfig.xml</configurationFile>--
>
<
configurationFile>
${basedir}/src/main/resources/mybatis/mysqlGeneratorConfig.xml
</configurationFile
>
<
configurationFile>
${basedir}/src/main/resources/mybatis/oracleGeneratorConfig.xml
</configurationFile
>
<
!--<configurationFile>${basedir}/src/main/resources/mybatis/oracleGeneratorConfig.xml</configurationFile>--
>
<!--<configurationFile>${basedir}/src/main/resources/mybatis/postgresqlGeneratorConfig1.xml</configurationFile>-->
<!--<configurationFile>${basedir}/src/main/resources/mybatis/postgresqlGeneratorConfig1.xml</configurationFile>-->
<!--postgresqlGeneratorConfig.xml-->
<!--postgresqlGeneratorConfig.xml-->
<verbose>
true
</verbose>
<verbose>
true
</verbose>
...
...
service/src/main/java/com/haomostudio/SeekTruthBackend/service/HmUtils/MybatisExampleHelper.java
View file @
1b7a89e9
...
@@ -3,7 +3,10 @@ package com.haomostudio.SeekTruthBackend.service.HmUtils;
...
@@ -3,7 +3,10 @@ package com.haomostudio.SeekTruthBackend.service.HmUtils;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.google.common.base.CaseFormat
;
import
org.springframework.web.context.ContextLoader
;
import
org.springframework.web.context.WebApplicationContext
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.*
;
import
java.util.*
;
...
@@ -61,6 +64,16 @@ public class MybatisExampleHelper {
...
@@ -61,6 +64,16 @@ public class MybatisExampleHelper {
return
null
;
return
null
;
}
}
public
static
Method
getMethodNumber
(
Object
obj
,
String
methodName
,
int
parameterNuber
){
for
(
Method
m:
obj
.
getClass
().
getDeclaredMethods
()){
if
(
m
.
getName
().
equals
(
methodName
)
&&
m
.
getParameterTypes
().
length
==
parameterNuber
){
return
m
;
}
}
return
null
;
}
/**
/**
* 给mybatis附加上某个字段的条件过滤
* 给mybatis附加上某个字段的条件过滤
* @param exampleObj
* @param exampleObj
...
@@ -202,4 +215,93 @@ public class MybatisExampleHelper {
...
@@ -202,4 +215,93 @@ public class MybatisExampleHelper {
}});
}});
}});
}});
}
}
/**
*
* @param m java反射类中的方法
* @param superior 实体类对象
* @param className 类名(用于反射时对应的ServiceImpl类)
* @param map 用于存储数据的Map
* @param table 关联表的名字
*/
public
static
void
dealSearchIncludes
(
Method
m
,
Object
superior
,
Object
className
,
Map
<
String
,
Object
>
map
,
String
table
,
String
packageName
){
try
{
if
(
m
!=
null
){
//外联表的主键值
Object
id
=
m
.
invoke
(
superior
);
//根据主键取出整条数据
if
(
id
!=
null
){
WebApplicationContext
wac
=
ContextLoader
.
getCurrentWebApplicationContext
();
//反射类名
Class
onwClass
=
Class
.
forName
(
packageName
+
"."
+
className
+
"ServiceImpl"
);
Object
impl
=
onwClass
.
newInstance
();
//获取Method的对象
String
get
=
"get"
;
if
(
className
.
equals
(
"CrmUser"
)){
get
=
"getUserById"
;
}
Method
m1
=
MybatisExampleHelper
.
getMethod
(
impl
,
get
);
if
(
m1
!=
null
){
//外联表的整条数据
Object
obj2
=
m1
.
invoke
(
wac
.
getBean
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Service"
),
id
);
//取出来的数据返回
map
.
put
(
table
.
toString
(),
obj2
);
}
}
}
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
}
public
static
void
dealSearchRefers
(
Object
id
,
String
table
,
Map
<
String
,
List
<
Object
>>
map
,
Object
obj
,
Object
className
,
String
packageName
){
try
{
//根据主键取出整条数据
if
(
id
!=
null
)
{
WebApplicationContext
wac
=
ContextLoader
.
getCurrentWebApplicationContext
();
//DivStattisTabService service = (DivStattisTabService)
//反射类名
Class
onwClass
=
Class
.
forName
(
packageName
+
"."
+
className
+
"ServiceImpl"
);
Object
impl
=
onwClass
.
newInstance
();
//获取Method的对象
Method
m1
=
MybatisExampleHelper
.
getMethodNumber
(
impl
,
"getListWithPagingAndFilter"
,
5
);
//filters的字符串拼接
StringBuffer
buffer
=
new
StringBuffer
();
buffer
.
append
(
"{"
);
buffer
.
append
(
"\""
+
table
+
"\""
);
buffer
.
append
(
":{"
);
buffer
.
append
(
"\""
+
obj
.
toString
()+
"\""
);
buffer
.
append
(
":{"
);
buffer
.
append
(
"\"equalTo\": \""
+
id
.
toString
()+
"\""
);
buffer
.
append
(
"} } }"
);
//执行getListWithPagingAndFilter方法的参数数组
Object
[]
methodObject
=
new
Object
[]{
1
,
1000
,
"id"
,
"asc"
,
buffer
.
toString
()};
if
(
m1
!=
null
){
//外联表的整条数据
List
<
Object
>
obj2
=
(
List
<
Object
>)
m1
.
invoke
(
wac
.
getBean
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Service"
),
1
,
1000
,
"id"
,
"asc"
,
buffer
.
toString
());
//取出来的数据返回
map
.
put
(
table
.
toString
(),
obj2
);
}
}
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
}
}
}
web/src/main/resources/mybatis/mysqlGeneratorConfig.xml
View file @
1b7a89e9
...
@@ -12,9 +12,9 @@
...
@@ -12,9 +12,9 @@
<plugin
type=
"org.mybatis.generator.plugins.ToStringPlugin"
/>
<plugin
type=
"org.mybatis.generator.plugins.ToStringPlugin"
/>
<jdbcConnection
driverClass=
"com.mysql.jdbc.Driver"
<jdbcConnection
driverClass=
"com.mysql.jdbc.Driver"
connectionURL=
"jdbc:mysql://
127.0.0.1:3306/power_saver_monitor
"
connectionURL=
"jdbc:mysql://
haomo-studio.com:3304/auction-oa
"
userId=
"root"
userId=
"root"
password=
"
123456
"
/>
password=
"
root
"
/>
<!-- 指定生成的类型为java类型,避免数据库中number等类型字段 -->
<!-- 指定生成的类型为java类型,避免数据库中number等类型字段 -->
<javaTypeResolver>
<javaTypeResolver>
...
...
web/src/main/resources/mybatis/oracleGeneratorConfig.xml
View file @
1b7a89e9
...
@@ -13,9 +13,9 @@
...
@@ -13,9 +13,9 @@
<plugin
type=
"org.mybatis.generator.plugins.ToStringPlugin"
/>
<plugin
type=
"org.mybatis.generator.plugins.ToStringPlugin"
/>
<jdbcConnection
driverClass=
"oracle.jdbc.driver.OracleDriver"
<jdbcConnection
driverClass=
"oracle.jdbc.driver.OracleDriver"
connectionURL=
"jdbc:oracle:thin:@
haomo-studio.com:21521:xe
"
connectionURL=
"jdbc:oracle:thin:@
172.21.20.39:1521:crmq02
"
userId=
"
HM_ORGANIZATION
"
userId=
"
crm
"
password=
"
123456
"
/>
password=
"
baidu2020
"
/>
<!-- 指定生成的类型为java类型,避免数据库中number等类型字段 -->
<!-- 指定生成的类型为java类型,避免数据库中number等类型字段 -->
<javaTypeResolver>
<javaTypeResolver>
...
@@ -45,7 +45,7 @@
...
@@ -45,7 +45,7 @@
value=
"false"
/>
value=
"false"
/>
</javaClientGenerator>
</javaClientGenerator>
<table
schema=
"
HM_ORGANIZATION
"
tableName=
"%"
>
<table
schema=
"
CRM
"
tableName=
"%"
>
<property
name=
"useActualColumnNames"
value=
"false"
/>
<property
name=
"useActualColumnNames"
value=
"false"
/>
<property
name=
"ignoreQualifiersAtRuntime"
value=
"true"
/>
<property
name=
"ignoreQualifiersAtRuntime"
value=
"true"
/>
</table>
</table>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment