java - 如何在java中调用带有另一个类的参数的方法?
问题描述
我遇到了一个问题,我想从一个类调用一个方法到另一个类,但是这个方法有一个参数。我尝试在String searchData = "searchValue"
我的另一堂课上做,但我的另一堂课没有被调用。
这是我的代码:
我要调用的方法
public List<JobSearchItem> getJobAutocomplete(String searchValue) {
String sValue = "%" + searchValue.toUpperCase() + "%";
return dataUtilityService.getJdbcTemplate().query(SQL_GET_JOB_SEARCH_LISTS,
new Object[]{sValue, sValue}, jobSearchItemMapper);
}
我想调用上述代码的另一种方法
public void loadSearchList() throws SQLException, NamingException, URISyntaxException, IOException, ParseException {
String searchData = "searchValue";
List<JobSearchItem> jobSearchList = XPayService.getJobAutocomplete(searchData);
this.setJobSearchItems(jobSearchList);
}
解决方案
你要么需要一个类的实例XPayService
来调用方法,要么你可以使方法静态
使用类的实例:
class XPayService() {
public List<JobSearchItem> getJobAutocomplete(String searchValue) {
String sValue = "%" + searchValue.toUpperCase() + "%";
return dataUtilityService.getJdbcTemplate().query(SQL_GET_JOB_SEARCH_LISTS,
new Object[]{sValue, sValue}, jobSearchItemMapper);
}
}
public void loadSearchList() throws SQLException, NamingException, URISyntaxException, IOException, ParseException {
XPayService xps = new XPayService();
String searchData = "searchValue";
List<JobSearchItem> jobSearchList = xps.getJobAutocomplete(searchData);
this.setJobSearchItems(jobSearchList);
}
使用静态方法:
class XPayService() {
public static List<JobSearchItem> getJobAutocomplete(String searchValue) {
String sValue = "%" + searchValue.toUpperCase() + "%";
return dataUtilityService.getJdbcTemplate().query(SQL_GET_JOB_SEARCH_LISTS,
new Object[]{sValue, sValue}, jobSearchItemMapper);
}
}
public void loadSearchList() throws SQLException, NamingException, URISyntaxException, IOException, ParseException {
String searchData = "searchValue";
List<JobSearchItem> jobSearchList = XPayService.getJobAutocomplete(searchData);
this.setJobSearchItems(jobSearchList);
}
推荐阅读
- visual-studio-code - 带有posix正斜杠的VSCode复制相对路径
- python - 使用 json 保存/加载 textRPG
- amazon-web-services - 使用管理员权限创建 S3 存储桶 AWS Toolkit for Visual Studio 时出错
- python - 如何在 Wagtail 中无头创建页面?
- python - 为什么在 Pi 的整数倍处对 torch.sin() 和 numpy.sin() 的评估有数量级?
- c - 将 UEFI 兼容软件加载到 USB 并运行它
- python - 读取 .bed 文件和以特定格式压缩输出的问题
- wpf - 仅当通过单击外部选择项目时才会触发与 ListBox.SelectedItem 的绑定
- swift - 使用完成处理程序在 Swift 中调用连续动画
- javascript - 如何成功路由到 Angular 中的其他组件?