试用
Spring-JDBC.我使用
this作为参考.我正在尝试获得一个名称相同的演员.运行此代码给了我所需的结果:
public List<String> getActorsWithSameLastName(String lastName,NamedParameterJdbcTemplate template) { String query = "SELECT FIRSTNAME FROM ACTORS WHERE LASTNAME=:LASTNAME"; Map<String,String> paramMap = new HashMap<String,String>(); paramMap.put("LASTNAME",lastName); return template.queryForList(query,paramMap,String.class); }
我有一个列表< String>的姓氏我如何获得一个列表的演员与我的列表?我是否迭代姓氏列表,并且每次调用getActorsWithSameLastName(),或者Spring提供了一种迭代方式,并为我获取结果?请指教.
解决方法
使用IN条款..
How to use SELECT IN clause in JDBCTemplates?
List<String> lastnames= new ArrayList(); Map namedParameters = Collections.singletonMap("lastnamevalues",lastnames); StringBuffer recordQueryString = new StringBuffer(); recordQueryString.append("select FIRSTNAME,LASTNAME from ACTORS where lastname in (:lastnamevalues) "); List nameInvolments = this.namedparameterJdbcTemplate.query(recordQueryString.toString(),namedParameters,new MyMapper());