扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
public class IBatisRentABike extends SqlMapDaoSupport
implements RentABike {
private String storeName ="";
public void setStoreName(String storeName) {
this.storeName= storeName;
}
public String getStoreName( ) {
return this.storeName;
}
public List getBikes() {
return getSqlMapTemplate().executeQueryForList("getBikes", null);
}
public Bike getBike(String serialNo) {
return (Bike) getSqlMapTemplate().
executeQueryForObject("getBikeBySerialNo", serialNo);
}
public Bike getBike(int bikeId) {
return (Bike) getSqlMapTemplate().
executeQueryForObject("getBikeByID", new Integer(bikeId));
}
public void saveBike(Bike bike) {
getSqlMapTemplate().executeUpdate("saveBike", bike);
}
public void deleteBike(Bike bike) {
getSqlMapTemplate().executeUpdate("deleteBike", bike);
}
public List getCustomers() {
return getSqlMapTemplate().executeQueryForList("getCustomers", null);
}
public Customer getCustomer(int custId) {
return (Customer) getSqlMapTemplate().
executeQueryForObject("getCustomer", new Integer(custId));
}
public List getReservations() {
return getSqlMaptemplate().
executeQueryForList("getReservations", null);
}
public List getReservations(Customer customer) {
return getSqlMaptemplate().
executeQueryForList("getReservationsForCustomer", customer);
}
public List getReservations(Bike bike) {
return getSqlMaptemplate().
executeQueryForList("getReservationsForBike",bike);
}
public List getReservations(Date date) {
return getSqlMaptemplate().
executeQueryForList("getReservationsForDate", date);
}
public Reservation getReservation(int resId) {
return getSqlMaptemplate().
executeQueryForObject("getReservation", new Integer(resId));
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<sql-map name="Bike" >
<result-map name="result" class="com.springbook.Bike" >
<property name="bikeId" column="bikeId" columnIndex="1" />
<property name="manufacturer" column="manufacturer" columnIndex="2" />
<property name="model" column="model" columnIndex="3" />
<property name="frame" column="frame" columnIndex="4" />
<property name="serialNo" column="serialNo" columnIndex="5" />
<property name="weight" column="weight" columnIndex="6" />
<property name="status" column="status" columnIndex="7" />
</result-map>
<mapped-statement name="getBikes" result-map="result">
select bikeId, manufacturer, model, frame, serialNo, status
from bikes
</mapped-statement>
<mapped-statement name="getBikeBySerialNo" result-map="result">
select bikeId, manufacturer, model, frame, serialNo, status
from bikes
where serialNo=#value#
</mapped-statement>
<mapped-statement name="getBikeByID" result-map="result">
select bikeId, manufacturer, model, frame, serialNo, weight, status
from bikes
where bikeId=#value#
</mapped-statement>
<mapped-statement name="saveBike" >
insert into bikes
(bikeId, manufacturer, model, frame, serialNo, weight, status)
values(#bikeId#, #manufacturer#, #model#, #frame#, #serialNo#,
#weight#, #status#)
</mapped-statement>
<mapped-statement name="deleteBike" >
delete from bikes
where bikeId = #bikeId#
</mapped-statement>
</sql-map>
<?xml version="1.0" encoding="UTF-8" ?>
<sql-map name="Customer" >
<result-map name="result" class="com.springbook.Customer" >
<property name="custId" column="custId" columnIndex="1" />
<property name="firstName" column="firstName" columnIndex="2" />
<property name="lastName" column="lastName" columnIndex="3" />
</result-map>
<mapped-statement name="getCustomers" result-map="result">
select custId,
firstName,
lastName
from customers
</mapped-statement>
<mapped-statement name="getCustomer" result-map="result">
select custId,
firstName,
lastName
from customers
where custId = #value#
</mapped-statement>
</sql-map>
<?xml version="1.0" encoding="UTF-8" ?>
<sql-map name="Reservation" >
<result-map name="result" class="com.springbook.Customer" >
<property name="reservationId" column="resId" columnIndex="1" />
<property name="bike" column="bikeId" columnIndex="2" />
<property name="customer" column="custId" columnIndex="3" />
<property name="reservationDate" column="resDate" columnIndex="4" />
</result-map>
<mapped-statement name="getReservations" result-map="result">
select resId,
bikeId,
custId,
resDate
from reservations
</mapped-statement>
<mapped-statement name="getReservationsForCustomer" result-map="result">
select resId,
bikeId,
custId,
resDate
from reservations
where custId = #value#
</mapped-statement>
<mapped-statement name="getReservationsForBike" result-map="result">
select resId,
bikeId,
custId,
resDate
from reservations
where bikeId = #value#
</mapped-statement>
<mapped-statement name="getReservationsForDate" result-map="result">
select resId,
bikeId,
custId,
resDate
from reservations
where resDate = #value#
</mapped-statement>
<mapped-statement name="getReservation" result-map="result">
select resId,
bikeId,
custId,
resDate
from reservations
where resId = #value#
</mapped-statement>
</sql-map>
<mapped-statement name="saveBike" >
insert into bikes
(manufacturer, model, frame, serialNo, weight, status)
values(#manufacturer#, #model#, #frame#, #serialNo#, #weight#,
#status#)
</mapped-statement>
<beans>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost/bikestore</value>
</property>
<property name="username">
<value>bikestore</value>
</property>
</bean>
<bean id="rentaBike" class="com.springbook.IBatisRentABike">
<property name="storeName"><value>Bruce's Bikes</value></property>
<property name="dataSource"><ref local="dataSource"/></property>
<property name="sqlMap"><ref local="sqlMap"/></property>
</bean>
<bean id="sqlMap"
class="org.springframework.orm.ibatis.SqlMapFactoryBean">
<property name="configLocation">
<value>/WEB-INF/ibatis.config</value>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource"><ref local="dataSource"/></property>
</bean>
<?xml version="1.0" encoding="UTF-8"?>
<sql-map-config>
<sql-map resource="Bike.xml" />
<sql-map resource="Customer.xml" />
<sql-map resource="Reservation.xml" />
</sql-map-config>
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者