Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
springboot-cli
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
s_guodong
springboot-cli
Commits
b575638b
Commit
b575638b
authored
Oct 25, 2023
by
gechengyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交Smh注解方式代码样例
parent
0fcf0bf0
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
151 additions
and
11 deletions
+151
-11
pom.xml
pom.xml
+5
-2
Smh.java
src/main/java/com/brilliance/entity/Smh.java
+43
-0
LckMapper.java
src/main/java/com/brilliance/mapper/LckMapper.java
+4
-1
SmhMapper.java
src/main/java/com/brilliance/mapper/SmhMapper.java
+16
-0
LckServiceImpl.java
...main/java/com/brilliance/service/impl/LckServiceImpl.java
+13
-1
generatorConfig.xml
src/main/resources/generatorConfig.xml
+6
-6
mybatis-config-annotation.xml
src/main/resources/mybatis-config-annotation.xml
+27
-0
mybatis-config.xml
src/main/resources/mybatis-config.xml
+0
-1
MybatisTest.java
src/test/java/com/brilliance/test/MybatisTest.java
+37
-0
No files found.
pom.xml
View file @
b575638b
...
...
@@ -85,8 +85,11 @@
<artifactId>
ojdbc6
</artifactId>
<version>
11.2.0.3
</version>
</dependency>
<dependency>
<groupId>
javax.persistence
</groupId>
<artifactId>
persistence-api
</artifactId>
<version>
1.0
</version>
</dependency>
</dependencies>
...
...
src/main/java/com/brilliance/entity/Smh.java
0 → 100644
View file @
b575638b
package
com
.
brilliance
.
entity
;
import
javax.persistence.Column
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.util.Date
;
@Table
(
name
=
"smh"
)
public
class
Smh
{
@Id
@Column
(
name
=
"inr"
)
private
String
inr
;
@Column
(
name
=
"crtfrm"
)
private
String
crtfrm
;
@Column
(
name
=
"dattim"
)
private
Date
dattim
;
public
String
getInr
()
{
return
inr
;
}
public
void
setInr
(
String
smhinr
)
{
this
.
inr
=
smhinr
;
}
public
String
getCrtfrm
()
{
return
crtfrm
;
}
public
void
setCrtfrm
(
String
crtfrm
)
{
this
.
crtfrm
=
crtfrm
;
}
public
Date
getDattim
()
{
return
dattim
;
}
public
void
setDattim
(
Date
dateTime
)
{
this
.
dattim
=
dateTime
;
}
}
src/main/java/com/brilliance/mapper/LckMapper.java
View file @
b575638b
...
...
@@ -8,5 +8,7 @@ public interface LckMapper {
int
insertSelective
(
Lck
record
);
int
deleteByPrimaryKey
(
@Param
(
"txt"
)
String
txt
,
@Param
(
"nam"
)
String
nam
);
Lck
selectLck
(
@Param
(
"nam"
)
String
userName
,
@Param
(
"txt"
)
String
txtInfo
);
int
deleteByPrimaryKey
(
@Param
(
"txt"
)
String
txtInfo
,
@Param
(
"nam"
)
String
userName
);
}
\ No newline at end of file
src/main/java/com/brilliance/mapper/SmhMapper.java
0 → 100644
View file @
b575638b
package
com
.
brilliance
.
mapper
;
import
com.brilliance.entity.Smh
;
import
org.apache.ibatis.annotations.Insert
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
public
interface
SmhMapper
{
//@Select({"select * from user where age=#{age}"})
@Select
({
"select * from smh where inr= #{inr} "
})
Smh
selectSmh
(
@Param
(
"inr"
)
String
inr
);
@Insert
({
"insert into smh(inr,crtfrm,dattim) values (#{inr},#{crtfrm},#{dattim})"
})
int
insert
(
Smh
smh
);
}
\ No newline at end of file
src/main/java/com/brilliance/service/impl/LckServiceImpl.java
View file @
b575638b
...
...
@@ -4,6 +4,8 @@ import com.brilliance.entity.Lck;
import
com.brilliance.mapper.LckMapper
;
import
com.brilliance.service.LckService
;
import
org.apache.commons.lang.reflect.MethodUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -18,6 +20,7 @@ import java.util.Date;
*/
@Service
public
class
LckServiceImpl
implements
LckService
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
LckServiceImpl
.
class
);
@Autowired
private
LckMapper
lckMapper
;
...
...
@@ -38,10 +41,19 @@ public class LckServiceImpl implements LckService {
if
(
inrObj
==
null
)
{
return
false
;
}
String
inr
=
(
String
)
inrObj
;
lck
.
setTxt
(
modeType
+
inr
);
String
txt
=
modeType
+
inr
;
Lck
lck1
=
lckMapper
.
selectLck
(
userName
,
modeType
);
if
(
lck1
!=
null
){
logger
.
info
(
"lck has been exsist,lck txt=【"
+
lck1
.
getTxt
()+
"】"
);
return
false
;
}
logger
.
info
(
"logger test"
);
lck
.
setTxt
(
txt
);
lck
.
setNam
(
userName
);
lck
.
setDattim
(
new
Date
());
int
insert
=
lckMapper
.
insert
(
lck
);
if
(
insert
>
0
)
return
true
;
...
...
src/main/resources/generatorConfig.xml
View file @
b575638b
...
...
@@ -8,8 +8,8 @@
<properties
resource=
"dbConfig.properties"
></properties>
<
classPathEntry
location=
"E:\programFile\work\MavenRepository\com\oracle\ojdbc6\11.2.0.3\ojdbc6-11.2.0.3.jar"
/
>
<
!--<classPathEntry location="E:\programFile\work\MavenRepository\com\oracle\ojdbc6\11.2.0.3\ojdbc6-11.2.0.3.jar" />--
>
<classPathEntry
location=
"${jdbc.driverLocation}"
/>
<!--指定特定数据库的jdbc驱动jar包的位置-->
...
...
@@ -60,13 +60,13 @@
<!-- <property name="enableSubPackages" value="true"/>-->
</javaClientGenerator>
<
!--<
table schema="test" tableName="LCK" domainObjectName="Lck" enableCountByExample="false"
<table
schema=
"test"
tableName=
"LCK"
domainObjectName=
"Lck"
enableCountByExample=
"false"
enableUpdateByExample=
"false"
enableDeleteByExample=
"false"
enableSelectByExample=
"false"
selectByExampleQueryId="false"/>
-->
selectByExampleQueryId=
"false"
/>
<table
schema=
"test"
tableName=
"MPI"
domainObjectName=
"Mpi"
enableCountByExample=
"false"
<!--
<table schema="test" tableName="MPI" domainObjectName="Mpi" enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId=
"false"
/>
selectByExampleQueryId="false"/>
-->
<!--
<table schema="test" tableName="MPS" domainObjectName="Mps" enableCountByExample="false"
enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
...
...
src/main/resources/mybatis-config-annotation.xml
0 → 100644
View file @
b575638b
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties
resource=
"dbConfig.properties"
/>
<environments
default=
"development"
>
<environment
id=
"development"
>
<transactionManager
type=
"JDBC"
/>
<dataSource
type=
"POOLED"
>
<property
name=
"driver"
value=
"${jdbc.driverClass}"
/>
<property
name=
"url"
value=
"${jdbc.connectionURL}"
/>
<property
name=
"username"
value=
"${jdbc.userId}"
/>
<property
name=
"password"
value=
"${jdbc.password}"
/>
</dataSource>
</environment>
</environments>
<mappers>
<package
name=
"com/brilliance/mapper"
/>
<!--<mapper resource="com/brilliance/mapper/MpsMapper.xml"/>
<mapper resource="com/brilliance/mapper/MpiMapper.xml"/>
<mapper resource="com/brilliance/mapper/MpeMapper.xml"/>
<mapper resource="com/brilliance/mapper/LckMapper.xml"/>-->
</mappers>
</configuration>
src/main/resources/mybatis-config.xml
View file @
b575638b
...
...
@@ -19,7 +19,6 @@
<mappers>
<!-- <package name="mappers"/>-->
<!--<mapper resource="com/brilliance/mappers/MpsMapper.xml"/>-->
<mapper
resource=
"com/brilliance/mapper/MpsMapper.xml"
/>
<mapper
resource=
"com/brilliance/mapper/MpiMapper.xml"
/>
<mapper
resource=
"com/brilliance/mapper/MpeMapper.xml"
/>
...
...
src/test/java/com/brilliance/test/MybatisTest.java
View file @
b575638b
package
com
.
brilliance
.
test
;
import
com.brilliance.entity.Lck
;
import
com.brilliance.entity.Mpi
;
import
com.brilliance.entity.Mps
;
import
com.brilliance.entity.Smh
;
import
com.brilliance.mapper.LckMapper
;
import
com.brilliance.mapper.MpiMapper
;
import
com.brilliance.mapper.MpsMapper
;
import
com.brilliance.mapper.SmhMapper
;
import
com.brilliance.util.DbCommonUtil
;
import
org.apache.ibatis.io.Resources
;
import
org.apache.ibatis.session.SqlSession
;
...
...
@@ -12,9 +17,33 @@ import org.junit.Test;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.Date
;
public
class
MybatisTest
{
@Test
public
void
test_annotation
()
throws
Exception
{
String
resource
=
"mybatis-config-annotation.xml"
;
InputStream
inputStream
=
Resources
.
getResourceAsStream
(
resource
);
SqlSessionFactory
sqlSessionFactory
=
new
SqlSessionFactoryBuilder
().
build
(
inputStream
);
// sqlSessionFactory.getConfiguration().addMapper(MpsMapper.class);
//2. 获取SqlSession对象,用它来执行sql
SqlSession
openSession
=
sqlSessionFactory
.
openSession
();
SmhMapper
smhMapper
=
openSession
.
getMapper
(
SmhMapper
.
class
);
Smh
smh
=
smhMapper
.
selectSmh
(
"00001074"
);
System
.
out
.
println
(
smh
.
getDattim
());
System
.
out
.
println
(
smh
.
getInr
());
Smh
smh1
=
new
Smh
();
smh1
.
setInr
(
"TESTINR1"
);
smh1
.
setCrtfrm
(
"TTT"
);
smh1
.
setDattim
(
new
Date
());
int
insert
=
smhMapper
.
insert
(
smh1
);
System
.
out
.
println
(
"insert==="
+
insert
);
openSession
.
commit
();
openSession
.
close
();
}
@Test
public
void
test
()
throws
Exception
{
String
resource
=
"mybatis-config.xml"
;
...
...
@@ -35,12 +64,20 @@ public class MybatisTest {
SqlSession
openSession
=
DbCommonUtil
.
getSqlSession
();
MpsMapper
mpsMapper
=
openSession
.
getMapper
(
MpsMapper
.
class
);
int
cnt
=
mpsMapper
.
counterMps
(
">"
);
Mps
mps
=
mpsMapper
.
selectByPrimaryKey
(
"00000972"
);
System
.
out
.
println
(
mps
.
getLstdattim
());
System
.
out
.
println
(
"cnt="
+
cnt
);
MpiMapper
mpiMapper
=
openSession
.
getMapper
(
MpiMapper
.
class
);
Mpi
mpi
=
mpiMapper
.
getMpi
(
"CFIX2022080100000901"
,
"<"
);
System
.
out
.
println
(
mpi
.
getInr
());
LckMapper
lckMapper
=
openSession
.
getMapper
(
LckMapper
.
class
);
Lck
lck
=
lckMapper
.
selectLck
(
"bgUser4"
,
"mps00001421"
);
if
(
lck
!=
null
)
{
System
.
out
.
println
(
lck
.
getDattim
());
}
DbCommonUtil
.
close
(
openSession
);
}
}
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