81,091
社区成员
发帖
与我相关
我的任务
分享
public Book selectBook(String ISBN){
System.out.println(ISBN);
List list=this.getHibernateTemplate().find("from Book where ISBN=?",ISBN); //报错就是这一行
Book book=null;
if(list.size()>0)
{
book=(Book)list.get(0);
}
return book;
}
public interface BookDao {
public void addBook(Book book);
public void deleteBook(String ISBN);
public void updateBook(Book book);
public Book selectBook(String ISBN);
}
public interface StudentService {
public Student selectStudent(String readerId);
}
package org.dao.impl;
import java.util.List;
import org.dao.BookDAO.BookDao;
import org.model.Book;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class BookDaoImpl extends HibernateDaoSupport implements BookDao {
//查询图书信息
public Book selectBook(String isbn) {
// TODO Auto-generated method stub
List list = this.getHibernateTemplate().find("from Book where isbn=?",isbn);
Book book = null;
if(list.size()>0){
book=(Book)list.get(0);
}
return book;
}
//添加图书信息
public void addBook(Book book) {
// TODO Auto-generated method stub
this.getHibernateTemplate().save(book);
}
//删除图书信息
public void deleteBook(String isbn) {
// TODO Auto-generated method stub
this.getHibernateTemplate().delete(this.selectBook(isbn));
}
//修改图书信息
public void updateBook(Book book) {
// TODO Auto-generated method stub
this.getHibernateTemplate().update(book);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<property name="url"
value="jdbc:sqlserver://localhost:1433;databaseName=CH12Data">
</property>
<property name="username" value="sa"></property>
<property name="password" value="1680012"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">
true
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/model/Login.hbm.xml</value>
<value>org/model/Book.hbm.xml</value>
<value>org/model/Student.hbm.xml</value>
<value>org/model/Lend.hbm.xml</value></list>
</property></bean>
<bean id="StudentDAO" class="org.Dao.impl.StudentDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="LendDAO" class="org.Dao.impl.LendDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="BookDAO" class="org.Dao.impl.BookDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="LoginDAO" class="org.Dao.impl.LoginDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="bookservice" class="org.service.Impl.BookServiceImpl">
<property name="bookDao" ref="BookDAO"></property>
</bean>
<bean id="loginservice" class="org.service.Impl.LoginServiceImpl">
<property name="loginDao" ref="LoginDAO"></property></bean>
<bean id="studentservice" class="org.service.Impl.StudentServiceImpl">
<property name="studentDao" ref="StudentDAO"></property></bean>
<bean id="lendservice" class="org.service.Impl.LendServiceImpl">
<property name="lendDao" ref="LendDAO"></property></bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"></ref>
</property></bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager" ref="transactionManager"></property>
<property name="transactionAttributes">
<props>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>bookservice</value>
<value>studentservice</value>
<value>loginservice</value>
<value>lendservice</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean id="LoginAction" class="org.action.LoginAction">
<property name="loginservice" ref="loginservice"></property>
</bean>
<bean id="LendAction" class="org.action.LendAction">
<property name="lendservice" ref="lendservice"></property>
<property name="bookservice" ref="bookservice"></property>
<property name="studentservice" ref="studentservice"></property>
</bean>
<bean id="BookAction" class="org.action.BookAction">
<property name="bookservice" ref="bookservice"></property>
<property name="lendservice" ref="lendservice"></property>
</bean>
</beans>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="org.model.Book" table="book" schema="dbo" catalog="CH12Data">
<id name="isbn" type="java.lang.String">
<column name="ISBN" length="20" />
<generator class="assigned" />
</id>
<property name="bookName" type="java.lang.String">
<column name="bookName" length="40" not-null="true" />
</property>
<property name="author" type="java.lang.String">
<column name="author" length="20" not-null="true" />
</property>
<property name="publisher" type="java.lang.String">
<column name="publisher" length="20" not-null="true" />
</property>
<property name="price" type="java.lang.Double">
<column name="price" precision="53" scale="0" not-null="true" />
</property>
<property name="cnum" type="java.lang.Integer">
<column name="cnum" not-null="true" />
</property>
<property name="snum" type="java.lang.Integer">
<column name="snum" not-null="true" />
</property>
<property name="summary" type="java.lang.String">
<column name="summary" length="200" />
</property>
<property name="photo" type="java.lang.String">
<column name="photo" length="50" />
</property>
</class>
</hibernate-mapping>