首页 > 解决方案 > Spring Boot API 响应的变化

问题描述

我有一个 Spring Boot 应用程序,其中 Mongodb 作为数据库,Jenkins 作为 CI 服务器。这是 Jenkins 存储的数据示例:

{ 
  "_id" : ObjectId("60ed8d8482cd350a2cd9db28"), 
  "buildId" : "35", 
  "wokspace" : "/var/lib/jenkins/workspace/ACM-JENKINS-API", 
  "remoteUrl" : "http://172.16.4.105:7990/scm/jenkins/acm-jenkins-api.git", 
  "branch" : "origin/branch-youssef", 
  "type" : "back", 
  "date" : "2021-07-13 14:56:36", 
  "description" : "Démarré par l'utilisateur Youssef Boudaya", 
  "backupPath" : "/root/backups_api/backup_35", 
  "projectId" : "60ed8d6a24ac0a5cee63aafe" 
}

这是 API 响应:

{
    "id": "60ed8d8482cd350a2cd9db28",
    "build_id": "35",
    "workspace": null,
    "remote_url": "http://172.16.4.105:7990/scm/jenkins/acm-jenkins-api.git",
    "branch": "origin/branch-youssef",
    "description": "Démarré par l'utilisateur Youssef Boudaya",
    "type": "back",
    "date": "2021-07-13 14:56:36",
    "project_id": "60ed8d6a24ac0a5cee63aafe",
    "backup_path": "/root/backups_api/backup_35"
}

我想知道为什么列名有所不同。我在 Spring Boot 中的实体:

/** The id. */
private String id;

/** The build id. */
// Build id de jenkins
private String buildId;

/** The workspace. */
private String workspace;

/** The remote url. */
private String remoteUrl;

/** The branch. */
private String branch;

/** The description. */
private String description;

/** The type. */
private String type;

/** The date. */
private String date;

/** The project id. */
private String projectId;

/** The backup path. */
private String backupPath;

并且 DTO 具有模型类的确切结构。

标签: mongodbspring-bootjenkins

解决方案


Spring boot Entites Members 将大写字母转换为列名中的下划线。我的意思是 myName 将是数据库中的 my_name 这是行为


推荐阅读