当前位置:编程学习 > html/css >>

spring jdbcTemplate 使用占位符(?)的query方法进行多表查询

1 在spring 的配置文件中applicationContext.xml中,配置service,dao.(前台使用的是flex,把flex也配置上了。)

[html]
<bean id="busSuperCapityAnalyDao" class="com.tm.dao.impl.sjwj.BusSuperCapityAnalyDaoImpl"></bean> 
 <bean id="busSuperCapityAnalyService" class="com.tm.service.impl.sjwj.BusSuperCapityAnalyServiceImpl"> 
  <flex:remoting-destination /> 
 </bean> 

<bean id="busSuperCapityAnalyDao" class="com.tm.dao.impl.sjwj.BusSuperCapityAnalyDaoImpl"></bean>
 <bean id="busSuperCapityAnalyService" class="com.tm.service.impl.sjwj.BusSuperCapityAnalyServiceImpl">
  <flex:remoting-destination />
 </bean>

2 写service接口

[java]
/**
 * 车辆超级电容数据分析service
 * @author hanshibo
 */ 
public inte易做图ce BusSuperCapityAnalyService { 
    public List<BusSuperCapityDataModel>  queryBusSuperCapityData(String busno ,String startTime,String endTime); 

/**
 * 车辆超级电容数据分析service
 * @author hanshibo
 */
public inte易做图ce BusSuperCapityAnalyService {
 public List<BusSuperCapityDataModel>  queryBusSuperCapityData(String busno ,String startTime,String endTime);
}3 写service实现

[java]
/**
 * 车辆超级电容分析ServiceImpl
 * @author hanshibo
 *
 */ 
public class BusSuperCapityAnalyServiceImpl implements BusSuperCapityAnalyService{ 
    @Resource  
    private BusSuperCapityAnalyDao busSuperCapityAnalyDao; 
    public List<BusSuperCapityDataModel> queryBusSuperCapityData(String busno,String startTime ,String endTime) { 
         
        return busSuperCapityAnalyDao.queryBusSuperCapityData(busno, startTime, endTime); 
    } 
 

/**
 * 车辆超级电容分析ServiceImpl
 * @author hanshibo
 *
 */
public class BusSuperCapityAnalyServiceImpl implements BusSuperCapityAnalyService{
 @Resource
 private BusSuperCapityAnalyDao busSuperCapityAnalyDao;
 public List<BusSuperCapityDataModel> queryBusSuperCapityData(String busno,String startTime ,String endTime) {
  
  return busSuperCapityAnalyDao.queryBusSuperCapityData(busno, startTime, endTime);
 }

}4  写dao层接口

[java]
/**
 * 超级电容数据分析Dao
 * @author hanshibo
 *
 */ 
public inte易做图ce BusSuperCapityAnalyDao { 
 
    public List<BusSuperCapityDataModel> queryBusSuperCapityData(String busno,String startTime ,String endTime); 

/**
 * 超级电容数据分析Dao
 * @author hanshibo
 *
 */
public inte易做图ce BusSuperCapityAnalyDao {

 public List<BusSuperCapityDataModel> queryBusSuperCapityData(String busno,String startTime ,String endTime);
}5 写dao层实现。使用spring jdbcTemplate 的query方法,用占位符(?)查询。

[java]
/**
 * 车辆超级电容数据分析daoImpl
 * @author hanshibo
 *
 */ 
public class BusSuperCapityAnalyDaoImpl implements BusSuperCapityAnalyDao{ 
         @Resource 
    private JdbcTemplate jdbcTemplate; 
     
    private String partParam ; 
 
public List<BusSuperCapityDataModel> queryBusSuperCapityData(String busno, 
            String startTime, String endTime) { 
    List<BusSuperCapityDataModel> busList = null; 
         
    busList = new ArrayList<BusSuperCapityDataModel>(); 
         String params[]=new String[]{busno,startTime,endTime};  
         int[] types = new int[]{Types.VARCHAR,Types.VARCHAR,Types.VARCHAR};   
         busList=jdbcTemplate.query(getcurSql(),params,types, new SuperCapityDataMapper()); 
         return busList; 

 
private String getcurSql(){ 
String sqlStr=" select t.bus_job_no ,to_char(l.upload_time, 'YYYY-MM-DD HH24:MI:SS')      uploadTime,l.SINGLECAPAMAXVOL,l.CAPAMAXVOLTAGENO,l.SINGLECAPAMINVOL,l.CAPAMINVOLTAGENO,l.SINGLECAPAMAXTEM,l.SINGLECAPAMAXTEMNO,l.SINGLECAPAMINTEM, l.SINGLECAPAMINTEMNO" + 
" from tm_engine_basic_log l,tm_newenergy_bus_info t"+ 
" where t.bus_no =?"+ 
" and   l.upload_time between to_date(?, 'yyyy-mm-dd hh24:mi:ss') " + 
" and   to_date(?, 'yyyy-mm-dd hh24:mi:ss')" + 
" and l.bus_no = t.bus_no"; 
    return sqlStr ;  

 
        /**
     *RowMapper 取值
     */ 
    class SuperCapityDataMapper implements RowMapper<BusSuperCapityDataModel>{ 
 
        public BusSuperCapityDataModel mapRow(ResultSet rs, int rowID) 
                throws SQLException { 
            BusSuperCapityDataModel  bm = new BusSuperCapityDataModel(); 
            bm.setBusjobno(rs.getString("bus_job_no")); 
            bm.setUploadTime(rs.getString("uploadTime")); 
            bm.setCapaMaxVolTageNo(rs.getInt("CAPAMAXVOLTAGENO")); 
            bm.setCapaminVolTageNo(rs.getInt("CAPAMINVOLTAGENO")); 
            bm.setSingleCapaMaxtem(rs.getInt("SINGLECAPAMAXTEM")); 
            bm.setSingleCapaMaxVol(rs.getInt("SINGLECAPAMAXVOL")); 
            bm.setSingleCapaMinTemNo(rs.getInt("SINGLECAPAMINTEMNO")); 
            bm.setSingleCapaMinVol(rs.getInt("SINGLECAPAMINVOL")); 
            bm.setSingleCpaMaxTemNo(rs.getInt("SINGLECAPAMAXTEMNO")); 
            bm.setSingleCpaMinTem(rs.getInt("SINGLECAPAMINTEM")); 
            return bm; 
    &nb

补充:web前端 , HTML/CSS  ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,