Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
automatic-test
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
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
钟涨钱
automatic-test
Commits
3e0a4f02
Commit
3e0a4f02
authored
Sep 09, 2021
by
朽木不可雕也
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改mybatis的mapper构建方式
parent
69f59e92
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
43 deletions
+47
-43
Readme.md
+2
-2
bootstrap/pom.xml
+35
-3
public/src/main/java/com/zhiweidata/automatictest/publics/BeanContainer.java
+1
-37
public/src/main/resources/mybatis.xml
+9
-1
No files found.
Readme.md
View file @
3e0a4f02
...
@@ -18,4 +18,4 @@ bootstrap 模块的 com.zhiweidata.automatictest.bootstrap.AutomaticTestBootstra
...
@@ -18,4 +18,4 @@ bootstrap 模块的 com.zhiweidata.automatictest.bootstrap.AutomaticTestBootstra
所有模块的入口都需要实现 java.lang.Runnable 接口
所有模块的入口都需要实现 java.lang.Runnable 接口
mybatis的mapper xml文件扫描resources的mappers文件夹,所以请吧所有mapper xml都放在mappers文件夹下
mybatis mapper配置统一在
[
mybatis.xml
](
public/src/main/resources/mybatis.xml
)
中配置
\ No newline at end of file
\ No newline at end of file
bootstrap/pom.xml
View file @
3e0a4f02
...
@@ -38,12 +38,44 @@
...
@@ -38,12 +38,44 @@
<finalName>
automatic-test
</finalName>
<finalName>
automatic-test
</finalName>
<plugins>
<plugins>
<plugin>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.8.1
</version>
<configuration>
<source>
8
</source>
<target>
8
</target>
<encoding>
UTF-8
</encoding>
<compilerArguments>
<verbose/>
<!--需要引入一些jdk的工具包, 不然会报错-->
<bootclasspath>
${java.home}/lib/rt.jar${path.separator}${java.home}/lib/jce.jar
</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-assembly-plugin -->
<!--maven打包插件-->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-assembly-plugin
</artifactId>
<version>
3.3.0
</version>
<configuration>
<archive>
<manifest>
<mainClass>
com.zhiweidata.automatictest.bootstrap.AutomaticTestBootstrap
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<!--指定为jar打包模式-->
<descriptorRef>
jar-with-dependencies
</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<executions>
<!--指定打包时需要执行指令-->
<execution>
<execution>
<id>
make-assembly
</id>
<phase>
package
</phase>
<goals>
<goals>
<goal>
repackag
e
</goal>
<goal>
singl
e
</goal>
</goals>
</goals>
</execution>
</execution>
</executions>
</executions>
...
...
public/src/main/java/com/zhiweidata/automatictest/publics/BeanContainer.java
View file @
3e0a4f02
package
com
.
zhiweidata
.
automatictest
.
publics
;
package
com
.
zhiweidata
.
automatictest
.
publics
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.nio.charset.StandardCharsets
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.time.FastDateFormat
;
import
org.apache.commons.lang3.time.FastDateFormat
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.ibatis.builder.xml.XMLConfigBuilder
;
import
org.apache.ibatis.builder.xml.XMLMapperBuilder
;
import
org.apache.ibatis.io.Resources
;
import
org.apache.ibatis.io.Resources
;
import
org.apache.ibatis.session.Configuration
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.apache.ibatis.session.SqlSessionFactory
;
import
org.apache.ibatis.session.SqlSessionFactoryBuilder
;
import
org.apache.ibatis.session.SqlSessionFactoryBuilder
;
import
org.jetbrains.annotations.NotNull
;
import
org.quartz.Scheduler
;
import
org.quartz.Scheduler
;
import
org.quartz.SchedulerException
;
import
org.quartz.SchedulerException
;
import
org.quartz.impl.StdSchedulerFactory
;
import
org.quartz.impl.StdSchedulerFactory
;
...
@@ -79,38 +71,10 @@ public class BeanContainer {
...
@@ -79,38 +71,10 @@ public class BeanContainer {
SqlSessionFactoryBuilder
builder
=
new
SqlSessionFactoryBuilder
();
SqlSessionFactoryBuilder
builder
=
new
SqlSessionFactoryBuilder
();
// 先读取xml中的配置
// 先读取xml中的配置
XMLConfigBuilder
configBuilder
=
new
XMLConfigBuilder
(
new
InputStreamReader
(
inputStream
,
StandardCharsets
.
UTF_8
));
sqlSessionFactory
=
builder
.
build
(
inputStream
);
configBuilder
.
parse
();
Configuration
configuration
=
configBuilder
.
getConfiguration
();
// 扫描mapper
File
mappersDir
=
Resources
.
getResourceAsFile
(
"mappers"
);
scanMapper
(
mappersDir
,
configuration
);
sqlSessionFactory
=
builder
.
build
(
configuration
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
e
.
getMessage
(),
e
);
}
}
SQL_SESSION_FACTORY
=
sqlSessionFactory
;
SQL_SESSION_FACTORY
=
sqlSessionFactory
;
}
}
/**
* 扫描mapper
*/
private
static
void
scanMapper
(
@NotNull
File
file
,
@NotNull
Configuration
configuration
)
throws
IOException
{
if
(
file
.
isDirectory
())
{
File
[]
mappers
=
requireNonNull
(
file
.
listFiles
());
for
(
File
mapper
:
mappers
)
{
scanMapper
(
mapper
,
configuration
);
}
}
else
{
String
fileName
=
file
.
getName
();
if
(
".xml"
.
equals
(
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
))))
{
String
resource
=
file
.
toPath
().
toUri
().
toString
();
try
(
InputStream
inputStream
=
Resources
.
getUrlAsStream
(
resource
))
{
XMLMapperBuilder
mapperBuilder
=
new
XMLMapperBuilder
(
inputStream
,
configuration
,
resource
,
configuration
.
getSqlFragments
());
mapperBuilder
.
parse
();
}
}
}
}
}
}
public/src/main/resources/mybatis.xml
View file @
3e0a4f02
...
@@ -8,10 +8,17 @@
...
@@ -8,10 +8,17 @@
<transactionManager
type=
"JDBC"
/>
<transactionManager
type=
"JDBC"
/>
<dataSource
type=
"com.zhiweidata.automatictest.publics.HikariDataSourceFactory"
>
<dataSource
type=
"com.zhiweidata.automatictest.publics.HikariDataSourceFactory"
>
<property
name=
"driver"
value=
"com.mysql.cj.jdbc.Driver"
/>
<property
name=
"driver"
value=
"com.mysql.cj.jdbc.Driver"
/>
<property
name=
"url"
value=
"jdbc:mysql://192.168.0.119:3306/automatic_test?useSSL=FALSE&serverTimezone=Asia/Shanghai"
/>
<property
name=
"url"
value=
"jdbc:mysql://192.168.0.119:3306/automatic_test?useSSL=FALSE&serverTimezone=Asia/Shanghai"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"username"
value=
"root"
/>
<property
name=
"password"
value=
"z199809051593"
/>
<property
name=
"password"
value=
"z199809051593"
/>
</dataSource>
</dataSource>
</environment>
</environment>
</environments>
</environments>
<mappers>
<mapper
resource=
"mappers/BarrageCollectionTestTaskMapper.xml"
/>
<mapper
resource=
"mappers/BarrageExportResultMapper.xml"
/>
<mapper
resource=
"mappers/ServerResponseMessageMapper.xml"
/>
</mappers>
</configuration>
</configuration>
\ No newline at end of file
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