hibernate getHibernateTemplate为null
java:packagecom.myproject.daoImpl;importjava.util.List;importorg.hibernate.SQLQuery;i...
java:
package com.myproject.daoImpl;
import java.util.List;
import org.hibernate.SQLQuery;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.myproject.dao.LoginDao;
public class LoginDaoImpl extends HibernateDaoSupport implements LoginDao {
public String login(String username, String password) {
List list = getHibernateTemplate().find("from User where username='" + username + "' and password='" + password + "'");
if(null != list) {
System.out.println(list.get(0).toString());
return "success";
}
return "fail";
}
}
xml:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/ssh_iduq</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>com/myproject/bean/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="loginAction" class="com.myproject.action.LoginAction" scope="prototype">
<property name="loginService" ref="loginService"></property>
</bean>
<bean id="loginService" class="com.myproject.serviceImpl.LoginServiceImpl">
<property name="loginDao" ref="loginDao"></property>
</bean>
<bean id="loginDao" class="com.myproject.daoImpl.LoginDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
请大家帮忙看看,非常感谢! 展开
package com.myproject.daoImpl;
import java.util.List;
import org.hibernate.SQLQuery;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.myproject.dao.LoginDao;
public class LoginDaoImpl extends HibernateDaoSupport implements LoginDao {
public String login(String username, String password) {
List list = getHibernateTemplate().find("from User where username='" + username + "' and password='" + password + "'");
if(null != list) {
System.out.println(list.get(0).toString());
return "success";
}
return "fail";
}
}
xml:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:mysql://localhost:3306/ssh_iduq</value>
</property>
<property name="username">
<value>root</value>
</property>
<property name="password">
<value>root</value>
</property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>com/myproject/bean/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="loginAction" class="com.myproject.action.LoginAction" scope="prototype">
<property name="loginService" ref="loginService"></property>
</bean>
<bean id="loginService" class="com.myproject.serviceImpl.LoginServiceImpl">
<property name="loginDao" ref="loginDao"></property>
</bean>
<bean id="loginDao" class="com.myproject.daoImpl.LoginDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
</beans>
请大家帮忙看看,非常感谢! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询