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

原创
2017/07/26 10:22
阅读数 151

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;
    }

应该还有其他方式,欢迎交流。。

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
1 收藏
1
分享
返回顶部
顶部