提交 f198470d 编写于 作者: M MaxKey

MybatisJpaContext

上级 dfd767aa
......@@ -26,9 +26,9 @@ import org.dromara.mybatis.jpa.entity.JpaEntity;
import org.dromara.mybatis.jpa.entity.JpaPageResults;
import org.dromara.mybatis.jpa.entity.PageResultsSqlCache;
import org.dromara.mybatis.jpa.query.Query;
import org.dromara.mybatis.jpa.spring.MybatisJpaContext;
import org.dromara.mybatis.jpa.util.BeanUtil;
import org.dromara.mybatis.jpa.util.InstanceUtil;
import org.dromara.mybatis.jpa.util.MybatisJpaContext;
import org.dromara.mybatis.jpa.util.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
......@@ -15,10 +15,11 @@
*/
package org.dromara.mybatis.jpa.util;
package org.dromara.mybatis.jpa.spring;
import java.time.LocalDateTime;
import org.apache.commons.lang.SystemUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
......@@ -106,7 +107,12 @@ public final class MybatisJpaContext {
* @return HttpServletRequest
*/
public static HttpServletRequest getRequest(){
return ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
ServletRequestAttributes servletRequestAttributes =(ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
if(servletRequestAttributes != null) {
return servletRequestAttributes.getRequest();
}else {
return null;
}
}
/**
......@@ -127,31 +133,32 @@ public final class MybatisJpaContext {
public static String version() {
if(VERSION == null) {
StringBuffer version =
new StringBuffer("---------------------------------------------------------------------------------\n");
version.append("+ MyBatis JPA Extra \n");
version.append("+\n");
version.append(String.format("+ %sCopyright 2018 - %s https://gitee.com/dromara/mybatis-jpa-extra/\n",
(char)0xA9 , new DateTime().getYear()
));
version.append("+ Licensed under the Apache License, Version 2.0 \n");
version.append("---------------------------------------------------------------------------------\n");
version.append("+ JAVA \n");
version.append(String.format("+ %s java version %s, class %s\n",
SystemUtils.JAVA_VENDOR,
SystemUtils.JAVA_VERSION,
SystemUtils.JAVA_CLASS_VERSION
));
version.append(String.format("+ %s (build %s, %s)\n",
SystemUtils.JAVA_VM_NAME,
SystemUtils.JAVA_VM_VERSION,
SystemUtils.JAVA_VM_INFO
));
version.append("---------------------------------------------------------------------------------\n");
VERSION = version.toString();
return
String.format("""
---------------------------------------------------------------------------------
- JAVA
- %s java version %s, class %s
- %s (build %s, %s)
---------------------------------------------------------------------------------
- MyBatis JPA Extra
-
- %sCopyright 2018 - %s https://gitee.com/dromara/mybatis-jpa-extra/
-
- Licensed under the Apache License, Version 2.0
---------------------------------------------------------------------------------
""",
SystemUtils.JAVA_VENDOR,
SystemUtils.JAVA_VERSION,
SystemUtils.JAVA_CLASS_VERSION,
SystemUtils.JAVA_VM_NAME,
SystemUtils.JAVA_VM_VERSION,
SystemUtils.JAVA_VM_INFO,
(char)0xA9,
LocalDateTime.now().getYear()
);
}
return VERSION;
}
}
/*
* Copyright [2021] [MaxKey of copyright http://www.maxkey.top]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dromara.mybatis.jpa.util;
package org.dromara.mybatis.jpa.util;
import org.dromara.mybatis.jpa.spring.MybatisJpaContext;
import org.junit.jupiter.api.Test;
public class JpaSpringContextTest {
@Test
public void version(){
System.out.println(MybatisJpaContext.version());
}
}
......@@ -19,9 +19,9 @@ package org.dromara.mybatis.jpa.test;
import org.dromara.mybatis.jpa.entity.JpaPageResults;
import org.dromara.mybatis.jpa.id.SerialGenerator;
import org.dromara.mybatis.jpa.spring.MybatisJpaContext;
import org.dromara.mybatis.jpa.test.dao.service.StudentsService;
import org.dromara.mybatis.jpa.test.entity.Students;
import org.dromara.mybatis.jpa.util.MybatisJpaContext;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......
......@@ -20,9 +20,9 @@ package org.dromara.mybatis.jpa.test;
import java.util.ArrayList;
import java.util.List;
import org.dromara.mybatis.jpa.spring.MybatisJpaContext;
import org.dromara.mybatis.jpa.test.dao.service.StudentsService;
import org.dromara.mybatis.jpa.test.entity.Students;
import org.dromara.mybatis.jpa.util.MybatisJpaContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
......
......@@ -3,8 +3,8 @@ package org.dromara.mybatis.jpa.test;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.dromara.mybatis.jpa.spring.MybatisJpaContext;
import org.dromara.mybatis.jpa.test.dao.service.StudentsService;
import org.dromara.mybatis.jpa.util.MybatisJpaContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册