Quellcode durchsuchen

mybatis组件自测及优化

yucheng vor 3 Jahren
Ursprung
Commit
f06ec1027a

+ 1 - 1
dc-cloud/dc-file/src/main/java/com/persagy/dc/file/service/impl/FileServiceImpl.java

@@ -22,7 +22,7 @@ import java.util.List;
  * @date 2021-05-15
  */
 @Service
-@Transactional
+@Transactional(rollbackFor = Exception.class)
 public class FileServiceImpl extends ServiceImpl<FileMapper, FileInfo> implements IFileService {
 
     @Override

+ 5 - 0
dc-comp/dc-mybatis/pom.xml

@@ -25,5 +25,10 @@
             <groupId>com.baomidou</groupId>
             <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
         </dependency>
+        <!-- mysql -->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+        </dependency>
     </dependencies>
 </project>

+ 2 - 0
dc-comp/dc-mybatis/src/main/java/com/persagy/dc/mybatis/config/MybatisPlusConfig.java

@@ -3,6 +3,7 @@ package com.persagy.dc.mybatis.config;
 import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
 import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer;
 import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
+import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
@@ -16,6 +17,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
  * @description 由 Mybatisplus Code Generator 创建
  * @since 2020-09-09 09:13:27
  **/
+@MapperScan(value = "com.persagy.**.dao")
 @Configuration
 @EnableTransactionManagement
 public class MybatisPlusConfig {

+ 0 - 44
dc-comp/dc-mybatis/src/main/java/com/persagy/dc/mybatis/typehandler/PsDateTimeStampTypeHandler.java

@@ -1,44 +0,0 @@
-package com.persagy.dc.mybatis.typehandler;
-
-import cn.hutool.core.util.StrUtil;
-import com.persagy.dc.common.lang.PsDateTime;
-import org.apache.ibatis.type.BaseTypeHandler;
-import org.apache.ibatis.type.JdbcType;
-import org.apache.ibatis.type.MappedJdbcTypes;
-import org.apache.ibatis.type.MappedTypes;
-
-import java.sql.*;
-import java.util.Date;
-
-/**
- * Mybatis日期时间全局处理
- * @author Charlie Yu
- * @version 1.0 2021-04-08
- */
-@MappedJdbcTypes(JdbcType.TIMESTAMP)
-@MappedTypes(PsDateTime.class)
-public class PsDateTimeStampTypeHandler extends BaseTypeHandler<PsDateTime> {
-
-    @Override
-    public void setNonNullParameter(PreparedStatement preparedStatement, int i, PsDateTime psDateTime, JdbcType jdbcType) throws SQLException {
-        preparedStatement.setTimestamp(i, new Timestamp(psDateTime.getMillis()));
-    }
-
-    @Override
-    public PsDateTime getNullableResult(ResultSet resultSet, String s) throws SQLException {
-        Timestamp timestamp = resultSet.getTimestamp(s);
-        return PsDateTime.parsePsDateTime(timestamp);
-    }
-
-    @Override
-    public PsDateTime getNullableResult(ResultSet resultSet, int i) throws SQLException {
-        Timestamp timestamp = resultSet.getTimestamp(i);
-        return PsDateTime.parsePsDateTime(timestamp);
-    }
-
-    @Override
-    public PsDateTime getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
-        Timestamp timestamp = callableStatement.getTimestamp(i);
-        return PsDateTime.parsePsDateTime(timestamp);
-    }
-}

+ 0 - 6
dc-server/pom.xml

@@ -28,11 +28,5 @@
             <artifactId>spring-cloud-commons</artifactId>
             <scope>compile</scope>
         </dependency>
-        <dependency>
-            <groupId>org.mybatis</groupId>
-            <artifactId>mybatis-spring</artifactId>
-            <version>2.0.3</version>
-            <scope>compile</scope>
-        </dependency>
     </dependencies>
 </project>

+ 0 - 1
dc-server/src/main/java/com/persagy/ServerApplication.java

@@ -21,7 +21,6 @@ import org.springframework.context.annotation.Configuration;
 @Configuration
 @EnableSpringUtil
 @SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
-@MapperScan(value = "com.persagy.dc.*.dao")
 public class ServerApplication {
 
     public static void main(String[] args) {