【发布时间】:2017-11-12 03:22:30
【问题描述】:
我尝试返回带有输入单词的数据列表,但它返回 null
public List<people> peoples(String l) {
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
try {
String sql = "select * from people where peopleName like '?' ;";
List<people> peoples = jdbcTemplate.query(sql, new Object[]{"%"+l+"%"},
new BeanPropertyRowMapper<>(people.class));
return peoples;
} catch (DataAccessException e) {
}catch(NullPointerException nullPointer) {
}
return null;
}
【问题讨论】:
-
您遇到了什么错误?
-
你得到空值,因为有一些异常,买你隐藏它,在控制台/日志中看不到任何东西。你有两个 catch 块,它们是空的。添加 printStacktrace() 你会明白为什么你会得到 null
-
@avisheks 它没有显示任何错误只是它返回 null
-
@sbjavateam 好吧我试试
标签: mysql sql spring-data spring-jdbc jdbctemplate