日期:2014-05-17 浏览次数:20759 次
public class UserDao extends HibernateDaoSupport {
//普通用户登录验证
@SuppressWarnings("unchecked")
public boolean checkUser(String userName,String userPassword){
boolean flag = false;
String hql = "from Userinfo as user where user.username = '"+userName+"' and user.userpassword = '"+userPassword+"'";
List<Userinfo> userList = this.getHibernateTemplate().find(hql);
if(userList.size()>0){
flag = true;
}
return flag;
}
<?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">
<!--指明hibernate配置文件的位置 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!--定义DAO -->
<bean id="userDao" class="com.dao.UserDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 配置LoginAction.java类文件 -->
<bean id="LoginAction" class="com.action.LoginAction" scope="prototype">
<property name="userDao">
<ref bean="userDao"/>
</property>
</bean>
</beans>
<hibernate-mapping>
<class name="com.bean.Userinfo" table="userinfo" catalog="test">
<id name="userName" type="java.lang.String">
<column name="userName" length="6" />
<generator class="identity" />
</id>
<property name="userPassword" type="java.lang.String">
<column name="userPassword" length="45" not-null="true" />
</property>
<property name="userRole" type="java.lang.Integer">
<column name="userRole" not-null="true" />
</property>
</class&