问题
Please bare with my limited info on code since having limited access to copy paste complete code.
@Repository("BaseDao")
public class BaseDaoImpl implements BaseDao{
public NamedParameterJdbcTemplate namedJdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource){
this.namedJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}
}
@Repository("WelcomeDao")
public class WelcomeDaoImpl extends BaseDaoImpl implements WelcomeDao {
public List<String> getFunctionTypes() {
SqlParameterSource paramSource = new MapSqlParameterSource();
paramSource .addValue("function_id", "FRS047");
paramSource .addValue("user_id", "DWHJAVA");
String query = "select distinct FUNCTION_TYPE from EX_VIEW where FUNCTION_ID = :function_id and USER_ID = :user_id ";
List<String> funTypes = this.namedJdbcTemplate.queryForList(query, paramSource,String.class);
return funTypes;
}
}
I also tried replacing SqlParameterSource with plain Map but no luck!!
I cannot get the results by executing the above query whereas instead of named parameters if I replace with hardcoded values in query, am able to retrieve the results!!
Please help what's wrong with my way of substituting parameters?
I frustrated and finally want to give up NamedParameterJdbcTemplate..
来源:https://stackoverflow.com/questions/29924774/spring-namedparameterjdbctemplate-not-returning-result-for-simple-query