SpringBoot 项目集成达梦数据库

1、Maven 引入相关依赖


    com.dameng
    Dm7JdbcDriver18
    7.6.0.165


    com.dameng
    DmDialect-for-hibernate5.3
    8.1.1.49
 

    org.springframework.boot
    spring-boot-starter-data-jpa
    ${spring.boot.version}


    com.alibaba
    druid-spring-boot-starter
    1.1.10

2、SpringBoot 配置文件相关配置

spring:
  datasource:
    url: jdbc:dm://192.168.28.48:5236
    username: JP
    password: 123456789
    driver-class-name: dm.jdbc.driver.DmDriver
    type: com.alibaba.druid.pool.DruidDataSource
    initialSize: 1
    minIdle: 3
    maxActive: 20
    maxWait: 60000
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 30000
    filters: stat,wall
    druid:
      test-while-idle: false
  jpa:
    show-sql: true
    generate-ddl: false
    hibernate:
      ddl-auto:
    properties:
      hibernate:
        enable_lazy_load_no_trans: true
        default_schema: JP
        temp:
          use_jdbc_metadata_defaults: false
    database-platform: org.hibernate.dialect.DmDialect

3、创建数据库实体

package cn.org.jp.common.db;

import java.math.BigInteger;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Entity
@Builder
@Table(name = "JP_OPERATION_LOG")
@NoArgsConstructor
@AllArgsConstructor
public class OperationLog {

  /**
   * ID
   */
  @Id
  @Column(name = "ID")
  private Integer id;

  /**
   * 租户 ID
   */
  @Column(name = "TENANT_ID")
  private String tenantId;

  /**
   * 应用模块
   */
  @Column(name = "MODULE")
  private String module;

  /**
   * 业务对象
   */
  @Column(name = "BUSINESS_OBJ")
  private String businessObj;

  /**
   * 操作
   */
  @Column(name = "OPERATION")
  private String operation;

  /**
   * 用户类型
   */
  @Column(name = "USER_TYPE")
  private String userType;

  /**
   * 用户
   */
  @Column(name = "USER")
  private String user;

  /**
   * 用户姓名
   */
  @Column(name = "USER_REALNAME")
  private int userRealname;

  /**
   * 请求 URI
   */
  @Column(name = "REQUEST_URI")
  private String requestUri;

  /**
   * 请求方式
   */
  @Column(name = "REQUEST_METHOD")
  private String requestMethod;

  /**
   * 请求参数
   */
  @Column(name = "REQUEST_PARAMS")
  private Integer requestParams;



  /**
   * 请求 IP
   */
  @Column(name = "REQUEST_IP")
  private Integer requestIp;


  /**
   * 状态码
   */
  @Column(name = "STATUS_CODE")
  private Integer statusCode;


  /**
   * 错误信息
   */
  @Column(name = "ERROR_MSG")
  private Integer errorMsg;


  /**
   * 是否删除
   */
  @Column(name = "DELETED")
  private Integer deleted;


  /**
   * 创建时间
   */
  @Column(name = "CREATE_TIME")
  private Date createTime;
}

4、创建数据库操作接口

package cn.org.jp.common.repository;

import cn.org.jp.common.db.OperationLog;
import java.math.BigInteger;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;

@Repository
public interface OperationLogRepository extends JpaRepository,
    JpaSpecificationExecutor {

}

5、创建controller,注入操作接口Bean

@Slf4j
@RequestMapping({"*/file", "file"})
@RestController
public class FileController {

    @Autowired
    private FileService fileService;
    @Autowired
    private FileRepository fileRepository;

    @PostMapping("big/upload")
    public void upload(String name, String md5, Long size, Integer chunks, Integer chunk,
                       MultipartFile files[]) throws IOException {
        /*if (chunks != null && chunks != 0) {
            fileService.uploadWithBlock(name, md5,size,chunks,chunk,file);
        } else {
            fileService.upload(name, md5,file);
        }*/
     

你可能感兴趣的:(达梦,DM,Springboot,spring,boot,数据库,java)