67,513
社区成员
发帖
与我相关
我的任务
分享
public User findUserByNameAndPass(String username,String password)
{
List ul=getHibernateTemplate().find("select au from com.bean.User au where au.username='"+username+"' and au.password='"+password+"'");
if(ul.size()==1)
{
return (User)ul.get(0);
}
return null;
}
package com.bean;
public class User {
private Integer id;
private String username;
private String password;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
<hibernate-mapping>
<class name="com.bean.User" table="usertable">
<id name="id" type="java.lang.Integer">
<column name="id"/>
<generator class="assigned"/>
</id>
<property name="username" type="java.lang.String">
<column name="username" length="50"/>
</property>
<property name="password" type="java.lang.String">
<column name="password" length="50"/>
</property>
</class>
</hibernate-mapping>
<!-- 配置数据源 -->
<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;DatebaseName=DB_For_J2EE">
</property>
<property name="username" value="sa"></property>
<property name="password" value="1233365810"></property>
</bean>
<!-- 配置Hibernate -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<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>com/bean/User.hbm.xml</value>
</list>
</property>
</bean>