在构建Spring Boot API的过程中,我遇到了一点麻烦,我希望有人对Spring Boot在幕后的工作方式更加熟悉,可以为我提供一些建议。
我在控制器中有一个@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;
公共类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;
}
}
这是rest控制器返回的示例输出:
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的列似乎消失了。
答案 0 :(得分:1)
您的数据库列名为web_catalog_baseurl
,但您的bean属性名为webCatalogueBaseurl
。 catalog
与catalogue
的比较,因此对于bean映射器来说是不一样的。
将bean属性重命名为webCatalogBaseurl
private String webCatalogBaseurl;
public String getWebCatalogBaseurl() {
return webCatalogBaseurl;
}
public void setWebCatalogBaseurl(String webCatalogBaseurl) {
this.webCatalogBaseurl = webCatalogBaseurl;
}