JdbcTemplate使用SQL语句查询

Class:

package com.jdsy.crscal.oper.service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.jdbc.core.RowMapper;

public class OperTicketService {

public List getFileName(){
  List list =  new ArrayList();
  String sql = "select filename, " +
    "operateman," +
    "operatetime, " +
    "count(0) total," +
    "sum(decode(sendflag, 1, 1, 0)) cls," +
    "sum(decode(sendflag, 1, 0, 1)) wcls " +
    "from oper_ticket where sendflag = 0 group by filename, operateman, operatetime";
  list = (List) getJdbcTemplate().query(sql, new RowMapper(){
   public Object mapRow(ResultSet rs, int index) throws SQLException {
    // TODO Auto-generated method stub
    Map map = new HashMap();
    map.put("fileName", rs.getString(1));
    map.put("operateMan", rs.getString(2));
    map.put("operateTime", rs.getString(3));
    map.put("total", rs.getString(4));
    map.put("", rs.getString(3));
    return map;
   }
    });
  
  return list;
 } 

}

 

Spring配置文件:


  
   
  

  
   
    
     
    

    
     
    

   

  

  
   
    PROPAGATION_REQUIRED
    PROPAGATION_REQUIRED
   

  

 

 

你可能感兴趣的:(spring,sql,import,bean,list,hashmap,class)