您的位置:首页 > 编程语言 > Java开发

SpringJdbcTemplate之namedJdbcTemplate 处理in及多条件查询的几种方式:

2017-07-26 00:00 471 查看
SpringJdbcTemplate之namedJdbcTemplate 处理in查询及多条件查询的几种方式:

第一种方式:用对象传参

private static final String GETGUESSPERSONSP="select datenum from scok where datenum=   :updateTime  and seq in(:list)  ";

public List<Sock> getGuessPersonSp(List<Integer> intList ,int updateTime) {
SpVo vo = new SpVo();
vo.setUpdateTime(updateTime);
vo.setList(list);
SqlParameterSource ps=new BeanPropertySqlParameterSource(vo);
final List<Sock> list= new  ArrayList<Sock>();
this.getNamedJdbcTemplate().query(GETGUESSPERSONSP, ps,new RowCallbackHandler(){

[@Override](https://my.oschina.net/u/1162528)
public void processRow(ResultSet rs) throws SQLException {
Sock vo = new Sock();
vo.setDatenum(rs.getInt("datenum"));
list.add(vo);
}});
return list;
}

第二种方式:用Map传参

private static final String SELECT_POINTBYUSERID = "select pointFlag from perpo where pointid=:pointID AND objectID =:objectID and userID in(:list)";

public List<AdVO> getReturnHalfPoint(List<Integer> list, int pointID, String ObjectID) {
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("pointID", pointID);
parameters.addValue("objectID", ObjectID);
parameters.addValue("list", list);

List<AdVO> listVO = this.getNamedJdbcTemplate().query(SELECT_POINTBYUSERID, parameters, new RowMapper<AdVO>() {

[@Override](https://my.oschina.net/u/1162528)
public AdVO mapRow(ResultSet rs, int rowNum) throws SQLException {
AdVO point = new AdVO();
point.setPointflag(rs.getString("pointFlag"));
return point;
}
});
return listVO;
}

应该还有其他方式,欢迎交流。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息