java - spring jdbcTemplate 是否会删除 URL?

标签 java json oracle rest spring-boot

我在构建 Spring Boot API 的过程中遇到了一些小问题,我希望更熟悉 Spring Boot 在幕后工作原理的人能够给我一些建议。

我在 Controller 中有一个 @ResponseBody 标记的方法,它可以进行数据库查询并将结果编码为 JSON,如下所示:

    @RequestMapping(value = "/oneLibInfo",method = RequestMethod.GET)
    @ResponseBody
    List<LibInfo> getOneLibInfo(@RequestParam(required = true,value = "NUC")String NUC){

    List<LibInfo> libInfos = jdbcTemplate.query(
            "select o.organisation_id, o.name, a.alias, i.service_id, i.library_system_id, i.web_catalog_baseurl, ls.LIBRARY_SYSTEM_NAME,ls.LIBRARY_SYSTEM_VENDOR,ls.QUERY_PARAM_ISBN,ls.QUERY_PARAM_TITLE,ls.QUERY_PARAM_ISBN,ls.QUERY_PARAM_AUTHOR_TITLE\n" +
                    "from ALG1.LIBRARY_SYSTEM ls\n" +
                    "  INNER JOIN ALG1.ALG_INFORMATION i on i.LIBRARY_SYSTEM_ID = ls.LIBRARY_SYSTEM_ID\n" +
                    "  inner join dir.service s on s.service_id = i.service_id\n" +
                    "  inner join dir.organisation o on o.organisation_id = s.organisation_id\n" +
                    "  inner join dir.organisation_alias a on a.organisation_id = o.organisation_id\n" +
                    "where a.alias in (?)\n" +
                    "      and a.alias_type = 'Union catalogue symbol'",
            new Object[]{NUC}
            ,new BeanPropertyRowMapper<>(LibInfo.class,false)
    );
    return libInfos;
    }

在应用程序外部运行时,查询工作正常。

它在应用程序中也能正常工作,只是有一列无法返回:webCatalogueBaseURL。

顾名思义,该列包含一个 URL,返回未定义。 我一生都无法弄清楚为什么。以前有人遇到过这样的问题吗?

P.S:用于行映射的域类:

package au.gov.nla.deeplinkhelper.domain;

公共(public)类 LibInfo {

public LibInfo() {
}


public LibInfo(String name, String alias, String serviceId, String librarySystemId, String webCatalogueBaseurl, String librarySystemName, String librarySystemVendor, String queryParamIsbn, String queryParamTitle, String queryParamIssn, String queryParamAuthorTitle) {
    this.name = name;
    this.alias = alias;
    this.serviceId = serviceId;
    this.librarySystemId = librarySystemId;
    this.webCatalogueBaseurl = webCatalogueBaseurl;
    this.librarySystemName = librarySystemName;
    this.librarySystemVendor = librarySystemVendor;
    this.queryParamIsbn = queryParamIsbn;
    this.queryParamTitle = queryParamTitle;
    this.queryParamIssn = queryParamIssn;
    this.queryParamAuthorTitle = queryParamAuthorTitle;
}

String name;
String alias;
String serviceId;
String librarySystemId;
String webCatalogueBaseurl;
String librarySystemName;
String librarySystemVendor;
String queryParamIsbn;
String queryParamTitle;
String queryParamIssn;
String queryParamAuthorTitle;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getAlias() {
    return alias;
}

public void setAlias(String alias) {
    this.alias = alias;
}

public String getServiceId() {
    return serviceId;
}

public void setServiceId(String serviceId) {
    this.serviceId = serviceId;
}

public String getLibrarySystemId() {
    return librarySystemId;
}

public void setLibrarySystemId(String librarySystemId) {
    this.librarySystemId = librarySystemId;
}

public String getWebCatalogueBaseurl() {
    return webCatalogueBaseurl;
}

public void setWebCatalogueBaseurl(String webCatalogueBaseurl) {
    this.webCatalogueBaseurl = webCatalogueBaseurl;
}

public String getLibrarySystemName() {
    return librarySystemName;
}

public void setLibrarySystemName(String librarySystemName) {
    this.librarySystemName = librarySystemName;
}

public String getLibrarySystemVendor() {
    return librarySystemVendor;
}

public void setLibrarySystemVendor(String librarySystemVendor) {
    this.librarySystemVendor = librarySystemVendor;
}

public String getQueryParamIsbn() {
    return queryParamIsbn;
}

public void setQueryParamIsbn(String queryParamIsbn) {
    this.queryParamIsbn = queryParamIsbn;
}

public String getQueryParamTitle() {
    return queryParamTitle;
}

public void setQueryParamTitle(String queryParamTitle) {
    this.queryParamTitle = queryParamTitle;
}

public String getQueryParamIssn() {
    return queryParamIssn;
}

public void setQueryParamIssn(String queryParamIssn) {
    this.queryParamIssn = queryParamIssn;
}

public String getQueryParamAuthorTitle() {
    return queryParamAuthorTitle;
}

public void setQueryParamAuthorTitle(String queryParamAuthorTitle) {
    this.queryParamAuthorTitle = queryParamAuthorTitle;
}

}

这是从其余 Controller 返回的示例输出:

data
:
Array(1)
0
:
alias
:
"NSCU:L"
librarySystemId
:
"1194"
librarySystemName
:
"Alma-test3 NSCU"
librarySystemVendor
:
"Ex libris"
name
:
"University Library Lismore"
queryParamAuthorTitle
:
null
queryParamIsbn
:
"$$ISBN$$&tab=Everything&search_scope=MyInst_and_CI&vid=61SCU_INST:61SCU&offset=0"
queryParamIssn
:
null
queryParamTitle
:
"$$TITLE$$&tab=Everything&search_scope=MyInst_and_CI&vid=61SCU_INST:61SCU&offset=0"
serviceId
:
"4216"
webCatalogueBaseurl
:
null

最后一项是有问题的。

这是使用 SpringBoot 2.01 和 Oracle DB。

似乎只有包含 URL 的列才消失。

最佳答案

您的数据库列名为 web_catalog_baseurl,但您的 Bean 属性名为 webCatalogueBaseurlcatalogcatalogue 所以对于 Bean 映射器来说它是不一样的。

将 bean 属性重命名为 webCatalogBaseurl

private String webCatalogBaseurl;

public String getWebCatalogBaseurl() {
    return webCatalogBaseurl;
}

public void setWebCatalogBaseurl(String webCatalogBaseurl) {
    this.webCatalogBaseurl = webCatalogBaseurl;
}

关于java - spring jdbcTemplate 是否会删除 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51150366/

相关文章:

java - 如何发送以protocol buffers作为有效负载格式的HTTP请求?

java - 从 Java 中获取与 String 一样长的位

java - Encog 中使用反向传播的前馈网络

在 heroku 上部署 Java 应用程序

javascript - 从不同的键创建多层对象:value pairs

xml - 如何使用 Play 服务 XML 和 JSON! 2.0

json - 有没有办法在 Swift 中仅从 JSON 部分创建对象?

iphone - 使用适用于 ARM7 的 OCI

oracle - 如何将 Oracle JVM 参数添加到 Tomcat 执行

java - Spring Hibernate Template 执行方法为 Oracle 上的计数查询返回什么对象类型?