Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
MaxKey单点登录官方(MaxKeyTop)
Mybatis Jpa Extra
提交
5af1fa21
M
Mybatis Jpa Extra
项目概览
MaxKey单点登录官方(MaxKeyTop)
/
Mybatis Jpa Extra
9 个月 前同步成功
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Mybatis Jpa Extra
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5af1fa21
编写于
1月 15, 2023
作者:
M
MaxKey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
6806c39b
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
35 addition
and
63 deletion
+35
-63
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/PageResultsSqlCache.java
...main/java/org/apache/mybatis/jpa/PageResultsSqlCache.java
+7
-2
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/JpaBaseService.java
...va/org/apache/mybatis/jpa/persistence/JpaBaseService.java
+6
-6
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/util/MybatisJpaContext.java
...n/java/org/apache/mybatis/jpa/util/MybatisJpaContext.java
+11
-48
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/util/StringUtils.java
...rc/main/java/org/apache/mybatis/jpa/util/StringUtils.java
+4
-0
mybatis-jpa-extra-spring-boot-starter-test/src/test/java/org/apache/mybatis/jpa/test/MybatisJpaApplication.java
...va/org/apache/mybatis/jpa/test/MybatisJpaApplication.java
+2
-2
mybatis-jpa-extra-spring-boot-starter-test/src/test/java/org/apache/mybatis/jpa/test/MybatisJpaApplicationTest.java
...rg/apache/mybatis/jpa/test/MybatisJpaApplicationTest.java
+2
-2
mybatis-jpa-extra-test/src/test/java/org/apache/mybatis/jpa/test/InitContext.java
...rc/test/java/org/apache/mybatis/jpa/test/InitContext.java
+3
-3
未找到文件。
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/PageResultsSqlCache.java
浏览文件 @
5af1fa21
...
...
@@ -20,7 +20,9 @@ package org.apache.mybatis.jpa;
import
org.apache.ibatis.mapping.BoundSql
;
public
class
PageResultsSqlCache
{
String
sql
;
BoundSql
boundSql
;
...
...
@@ -29,18 +31,21 @@ public class PageResultsSqlCache {
this
.
sql
=
sql
;
this
.
boundSql
=
boundSql
;
}
public
String
getSql
()
{
return
sql
;
}
public
void
setSql
(
String
sql
)
{
this
.
sql
=
sql
;
}
public
BoundSql
getBoundSql
()
{
return
boundSql
;
}
public
void
setBoundSql
(
BoundSql
boundSql
)
{
this
.
boundSql
=
boundSql
;
}
}
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/persistence/JpaBaseService.java
浏览文件 @
5af1fa21
...
...
@@ -29,7 +29,7 @@ import org.apache.mybatis.jpa.query.Query;
import
org.apache.mybatis.jpa.util.BeanUtil
;
import
org.apache.mybatis.jpa.util.InstanceUtil
;
import
org.apache.mybatis.jpa.util.StringUtils
;
import
org.apache.mybatis.jpa.util.
JpaWeb
Context
;
import
org.apache.mybatis.jpa.util.
MybatisJpa
Context
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.github.benmanes.caffeine.cache.Cache
;
...
...
@@ -112,9 +112,9 @@ public class JpaBaseService <T extends JpaBaseEntity> {
public
IJpaBaseMapper
<
T
>
getMapper
()
{
try
{
if
(
mapper
==
null
)
{
String
mapperClassBean
=
mapperClass
.
toLowerCase
().
charAt
(
0
)
+
mapperClass
.
substring
(
1
);
String
mapperClassBean
=
StringUtils
.
firstToLowerCase
(
mapperClass
);
_logger
.
info
(
"mapperClass Bean is {}"
,
mapperClassBean
);
mapper
=
(
IJpaBaseMapper
<
T
>)
JpaWeb
Context
.
getBean
(
mapperClassBean
);
mapper
=
(
IJpaBaseMapper
<
T
>)
MybatisJpa
Context
.
getBean
(
mapperClassBean
);
}
}
catch
(
Exception
e
)
{
_logger
.
error
(
"getMapper Exception "
,
e
);
...
...
@@ -192,7 +192,7 @@ public class JpaBaseService <T extends JpaBaseEntity> {
Integer
count
=
0
;
try
{
if
(
entity
==
null
)
{
entity
=
(
T
)
entityClass
.
newInstance
();
entity
=
(
T
)
entityClass
.
getDeclaredConstructor
().
newInstance
();
}
count
=
getMapper
().
queryPageResultsCount
(
entity
);
_logger
.
debug
(
"queryCount count : {}"
,
count
);
...
...
@@ -211,7 +211,7 @@ public class JpaBaseService <T extends JpaBaseEntity> {
public
List
<
T
>
query
(
T
entity
)
{
try
{
if
(
entity
==
null
)
{
entity
=
(
T
)
entityClass
.
newInstance
();
entity
=
(
T
)
entityClass
.
getDeclaredConstructor
().
newInstance
();
}
return
getMapper
().
query
(
entity
);
}
catch
(
Exception
e
)
{
...
...
@@ -228,7 +228,7 @@ public class JpaBaseService <T extends JpaBaseEntity> {
@SuppressWarnings
(
"unchecked"
)
public
List
<
T
>
query
(
Query
query
)
{
try
{
return
getMapper
().
filterByQuery
((
T
)
entityClass
.
newInstance
(),
query
);
return
getMapper
().
filterByQuery
((
T
)
entityClass
.
getDeclaredConstructor
().
newInstance
(),
query
);
}
catch
(
Exception
e
)
{
_logger
.
error
(
"query Exception "
,
e
);
}
...
...
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/util/
JpaWeb
Context.java
→
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/util/
MybatisJpa
Context.java
浏览文件 @
5af1fa21
...
...
@@ -19,6 +19,7 @@ package org.apache.mybatis.jpa.util;
import
org.apache.commons.lang.SystemUtils
;
import
org.joda.time.DateTime
;
import
org.springframework.beans.BeansException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.core.env.StandardEnvironment
;
import
org.springframework.web.context.request.RequestContextHolder
;
...
...
@@ -36,13 +37,13 @@ import jakarta.servlet.http.HttpSession;
* @author Crystal.Sea
* @since 1.6
*/
public
final
class
JpaWeb
Context
{
public
final
class
MybatisJpa
Context
{
private
static
String
VERSION
=
null
;
public
static
StandardEnvironment
properties
;
public
static
ApplicationContext
applicationContext
=
null
;
public
static
ApplicationContext
applicationContext
=
null
;
/**
* get ApplicationContext from web ServletContext configuration
...
...
@@ -58,13 +59,20 @@ public final class JpaWebContext {
* @return Object
*/
public
static
Object
getBean
(
String
id
){
if
(
applicationContext
==
null
)
{
if
(
applicationContext
==
null
)
{
return
getApplicationContext
().
getBean
(
id
);
}
else
{
return
applicationContext
.
getBean
(
id
);
}
}
public
static
<
T
>
T
getBean
(
String
name
,
Class
<
T
>
requiredType
)
throws
BeansException
{
if
(
applicationContext
==
null
)
{
return
getApplicationContext
().
getBean
(
name
,
requiredType
);
}
else
{
return
applicationContext
.
getBean
(
name
,
requiredType
);
}
};
//below method is common HttpServlet method
/**
...
...
@@ -75,7 +83,6 @@ public final class JpaWebContext {
return
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
}
/**
* get current Session
* @return HttpSession
...
...
@@ -83,51 +90,7 @@ public final class JpaWebContext {
public
static
HttpSession
getSession
(){
return
getRequest
().
getSession
();
}
/**
* get current Session,if no session ,new Session created
* @return HttpSession
*/
public
static
HttpSession
getSession
(
boolean
create
)
{
return
getRequest
().
getSession
(
create
);
}
/**
* set Attribute to session ,Attribute name is name,value is value
* @param name
* @param value
*/
public
static
void
setAttribute
(
String
name
,
Object
value
){
getSession
().
setAttribute
(
name
,
value
);
}
/**
* get Attribute from session by name
* @param name
* @return
*/
public
static
Object
getAttribute
(
String
name
){
return
getSession
().
getAttribute
(
name
);
}
/**
* remove Attribute from session by name
* @param name
*/
public
static
void
removeAttribute
(
String
name
){
getSession
().
removeAttribute
(
name
);
}
/**
* get Request Parameter by name
* @param name
* @return String
*/
public
static
String
getParameter
(
String
name
){
return
getRequest
().
getParameter
(
name
);
}
public
static
String
version
()
{
if
(
VERSION
==
null
)
{
StringBuffer
version
=
...
...
mybatis-jpa-extra-core/src/main/java/org/apache/mybatis/jpa/util/StringUtils.java
浏览文件 @
5af1fa21
...
...
@@ -54,6 +54,10 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
}
return
num
;
}
public
static
String
firstToLowerCase
(
String
str
)
{
return
str
.
toLowerCase
().
charAt
(
0
)
+
str
.
substring
(
1
);
}
public
static
List
<
String
>
string2List
(
String
string
,
String
split
)
{
String
[]
strs
=
{};
...
...
mybatis-jpa-extra-spring-boot-starter-test/src/test/java/org/apache/mybatis/jpa/test/MybatisJpaApplication.java
浏览文件 @
5af1fa21
...
...
@@ -21,7 +21,7 @@ import org.apache.mybatis.jpa.id.SerialGenerator;
import
org.apache.mybatis.jpa.persistence.JpaPageResults
;
import
org.apache.mybatis.jpa.test.dao.service.StudentsService
;
import
org.apache.mybatis.jpa.test.entity.Students
;
import
org.apache.mybatis.jpa.util.
JpaWeb
Context
;
import
org.apache.mybatis.jpa.util.
MybatisJpa
Context
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -59,7 +59,7 @@ public class MybatisJpaApplication implements ApplicationRunner{
@Override
public
void
run
(
ApplicationArguments
args
)
throws
Exception
{
JpaWeb
Context
.
applicationContext
=
applicationContext
;
MybatisJpa
Context
.
applicationContext
=
applicationContext
;
_logger
.
info
(
"queryPageResults by mapperId..."
);
Students
student
=
new
Students
();
...
...
mybatis-jpa-extra-spring-boot-starter-test/src/test/java/org/apache/mybatis/jpa/test/MybatisJpaApplicationTest.java
浏览文件 @
5af1fa21
...
...
@@ -21,7 +21,7 @@ import java.util.ArrayList;
import
java.util.List
;
import
org.apache.mybatis.jpa.test.dao.service.StudentsService
;
import
org.apache.mybatis.jpa.test.entity.Students
;
import
org.apache.mybatis.jpa.util.
JpaWeb
Context
;
import
org.apache.mybatis.jpa.util.
MybatisJpa
Context
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.slf4j.Logger
;
...
...
@@ -47,7 +47,7 @@ public class MybatisJpaApplicationTest{
@BeforeEach
public
void
before
()
{
_logger
.
info
(
"---------------- before"
);
JpaWeb
Context
.
applicationContext
=
applicationContext
;
MybatisJpa
Context
.
applicationContext
=
applicationContext
;
}
...
...
mybatis-jpa-extra-test/src/test/java/org/apache/mybatis/jpa/test/InitContext.java
浏览文件 @
5af1fa21
...
...
@@ -4,7 +4,7 @@ import java.text.SimpleDateFormat;
import
java.util.Date
;
import
org.apache.mybatis.jpa.test.dao.service.StudentsService
;
import
org.apache.mybatis.jpa.util.
JpaWeb
Context
;
import
org.apache.mybatis.jpa.util.
MybatisJpa
Context
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.context.ApplicationContext
;
...
...
@@ -23,8 +23,8 @@ public class InitContext {
_logger
.
info
(
"Application dir "
+
System
.
getProperty
(
"user.dir"
));
context
=
new
ClassPathXmlApplicationContext
(
new
String
[]
{
"spring/applicationContext.xml"
});
JpaWeb
Context
.
applicationContext
=
context
;
StudentsService
service
=(
StudentsService
)
JpaWeb
Context
.
getBean
(
"studentsService"
);
MybatisJpa
Context
.
applicationContext
=
context
;
StudentsService
service
=(
StudentsService
)
MybatisJpa
Context
.
getBean
(
"studentsService"
);
return
service
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录