我似乎无法注入SQL查询字符串。
我使用的是JDBCTemplate,但我不习惯(我从另一个不同年份的团队中挑选了这个项目来进行改进)。 基本上,我像在项目中遇到的所有其他查询一样执行此操作,并且在哪里有“?”我期望插入一个值。 这是我的SQL查询字符串:
private static final String SELECT_BASE = "SELECT id, log_date AS logDate, access_type AS accessType, access_path AS accessPath, access_user AS accessUser, response_date AS responseDate, status, detail FROM ServerLog ORDER BY log_date ?;";
这是应该返回列表的函数。
public List<ServerLogDao> findAll(boolean ascending) {
return jdbcTemplate.query(SELECT_ALL, new BeanPropertyRowMapper<>(ServerLogDao.class), (ascending ? "ASC" : "DESC"));
}
我的spring exceptionHandler捕获了这个异常:
PreparedStatementCallback; bad SQL grammar [SELECT id, log_date AS logDate, access_type AS accessType, access_path AS accessPath, access_user AS accessUser, response_date AS responseDate, status, detail FROM ServerLog ORDER BY log_date ?]
如果语句中带有“?”,显然哪个不会运行。 我期望它返回的列表是升序还是降序。