【问题标题】:Data exists in DB but JPA returning blank, Spring?数据存在于数据库中,但 JPA 返回空白,Spring?
【发布时间】:2020-05-30 07:22:58
【问题描述】:

我正在查询数据库以获取结果,但我得到了空白数组

存储库类

@Repository
public interface AppConfigRepository extends CrudRepository<AppConfig, Long> {

@Query("SELECT n FROM AppConfig n WHERE n.appCode = ?1 and n.appVersion = ?2")
List<AppConfig> findByCodeAndVersion(String appCode, String appVersion);
}

表格类

@Entity
@Table(name = "app_config")
@EntityListeners(AuditingEntityListener.class)
public class AppConfig {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(columnDefinition = "serial")
private long id;
@Column(name = "app_code", nullable = false)
private String appCode;
@Column(name = "app_name", nullable = false)
private String appName;
@Column(name = "api_url", nullable = true)
private String apiUrl;
@Column(name = "db_name", nullable = true)
private String dbName;
@Column(name = "app_version", nullable = false)
private String appVersion;

映射函数

@RequestMapping(value = "/config", params = { "appCode", "appVersion" }, method = RequestMethod.GET)
public List<AppConfig> getConfig(@RequestParam(value = "appCode", required = true) String appCode,
        @RequestParam(value = "appVersion", required = true) String appVersion) {
    System.out.println(appCode);
    System.out.println(appVersion);
    return configRepository.findByCodeAndVersion(appCode, appCode);
}

这就是我制作网址的方式

http://localhost:9090/api/v1/config?appCode=MANDL_LIVE&appVersion=12.0

在我看到的日志中

select appconfig0_.id as id1_0_, appconfig0_.api_url as api_url2_0_, appconfig0_.app_code as app_code3_0_, appconfig0_.app_name as app_name4_0_, appconfig0_.app_version as app_vers5_0_, appconfig0_.db_name as db_name6_0_ from app_config appconfig0_ where appconfig0_.app_code=? and appconfig0_.app_version=?

【问题讨论】:

    标签: java sql spring jpa


    【解决方案1】:

    你在打电话:

    return configRepository.findByCodeAndVersion(appCode, appCode);
    

    不应该是:

    return configRepository.findByCodeAndVersion(appCode, appVersion);
    

    【讨论】:

      猜你喜欢
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      • 2019-03-31
      • 2022-01-21
      • 2017-09-06
      • 2017-05-26
      • 2015-06-30
      • 2019-06-08
      相关资源
      最近更新 更多