Spring JdbcTemplate

来源:互联网 发布:怎样领取淘宝优惠券 编辑:程序博客网 时间:2024/06/06 06:50

Spring 配置文件、

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tool="http://www.springframework.org/schema/tool"xmlns:security="http://www.springframework.org/schema/security"xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation="       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd       http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-4.0.xsd     http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd      http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-4.0.xsd      http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd     http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.0.xsd"><description>Spring相关配置 </description><context:component-scan base-package="com.study.dao" /><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"init-method="init" destroy-method="close"><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /></bean><!-- spring jdbc --><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="dataSource" /></bean></beans>

实现类

package com.study.dao.impl;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.jdbc.core.BeanPropertyRowMapper;import org.springframework.jdbc.core.JdbcTemplate;import org.springframework.stereotype.Component;import com.study.dao.ILoanFeeDaoJdbc;import com.study.entity.LoanFeeVo;@Componentpublic class LoanFeeDaoJdbcImpl implements ILoanFeeDaoJdbc {@Autowiredprivate JdbcTemplate jdbcTemplate;public LoanFeeVo getByFeeNo(String feeno) {String sql = "select * from S_LOAN_FEE t where t.fee_no="+feeno;System.out.println("sql========"+sql);List<LoanFeeVo> loanfeelist=(List<LoanFeeVo>) jdbcTemplate.query(sql, new BeanPropertyRowMapper(LoanFeeVo.class));System.err.println(loanfeelist.get(0).getFeeName());return loanfeelist.get(0);}}




0 0