zoukankan      html  css  js  c++  java
  • spring jdbcTemplate query

    1. spring jdbcTemplate query需要实现mapRow方法

    package com.cdv.apolloagent.jdbc.dao.impl;
    
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.List;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.jdbc.core.RowMapper;
    import org.springframework.stereotype.Repository;
    
    import com.cdv.apolloagent.jdbc.dao.TaskDao;
    import com.cdv.apolloagent.model.Task;
    @Repository
    public class TaskDaoImpl implements TaskDao {
    
        @Autowired
        private JdbcTemplate jdbcTemplate;
        @Override
        public List<Task> findTaskList(int flag, int limit, int max){
            String sql = "select t.* from task t where t.flag = ? limit ?,?";
            List<Object> params = new ArrayList<Object>();
            params.add(flag);
            params.add(limit);
            params.add(max);
            
            Object[] para = params.toArray(new Object[params.size()]);
            List<Task> taskList = this.jdbcTemplate.query(sql.toString(),para,
                    new RowMapper<Task>() {
                        public Task mapRow(ResultSet rs, int rowNum) throws SQLException {
                            Task task = new Task();
                            task.setId(rs.getLong("id"));
                            task.setWorkorderid(rs.getInt("workorderid"));
                            task.setFlag(rs.getInt("flag"));
                            return task;
                        }
                    });
            return taskList;
        }
    }
  • 相关阅读:
    ::before和::after伪元素的用法
    JS中map、some、every、filter方法
    C++多线程,互斥,同步
    RAII
    Proxy 代理
    Decorator 装饰
    TCP和UDP的9个区别是什么
    谈谈自己对面向对象的理解
    C++11多线程
    std::move
  • 原文地址:https://www.cnblogs.com/rocky-fang/p/5501614.html
Copyright © 2011-2022 走看看