67,513
社区成员
发帖
与我相关
我的任务
分享
public String login() throws Exception{
System.out.print(users.getUname());
System.out.print(users.getUpwd());
try {
Users loginUser=loginservice.login(users.getUname(),users.getUpwd());
if(loginUser!=null){
ActionContext context=ActionContext.getContext();
context.getSession().put("LOGINUSER", loginUser);
return SUCCESS;
}
} catch (Exception e) {
log.error("登录查询失败", e);
return ERROR;
}
return INPUT;
}
public Users login(String uname,String upass){
List list=usersDAO.findByUname(uname);
if(list==null ||list.size()==0){
return null;
}
Users users=(Users)usersDAO.findByUname(uname).get(0);
if(users==null){
return null;
}
if(uname.equals(users.getUname())&&upass.equals(users.getUpwd())){
return users;
}else{
return null;
}
}
public List findByUname(Object uname) {
return findByProperty(UNAME, uname);
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding Users instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Users as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
<!-- 配置DAO组件的父模板 -->
<bean id="daoTemplate" abstract="true">
<!-- 注入sessionFactory引用 -->
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 流水号 -->
<bean id="sequenceDao" parent="daoTemplate" class="com.cms.dao.impl.SequenceDaoImpl" />
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/redwooddb">
</property>
<property name="username" value="root"></property>
<property name="password" value="123654"></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.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/foraise/entity/Furnituretype.hbm.xml</value>
<value>com/foraise/entity/Redwoodparameter.hbm.xml</value>
<value>com/foraise/entity/Images.hbm.xml</value>
<value>com/foraise/entity/News.hbm.xml</value>
<value>com/foraise/entity/Users.hbm.xml</value></list>
</property></bean>
<bean id="FurnituretypeDao"
class="com.foraise.dao.impl.FurnituretypeDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="RedwoodparameterDao"
class="com.foraise.dao.impl.RedwoodparameterDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="ImagesDao" class="com.foraise.dao.impl.ImagesDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="NewsDao" class="com.foraise.dao.impl.NewsDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="UsersDao" class="com.foraise.dao.impl.UsersDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="LoginService" class="com.foraise.service.impl.LoginService">
<property name="usersDao" ref="UsersDao"/>
</bean>
<bean id="LoginAction" class="com.foraise.action.LoginAction">
<property name="loginservice" ref="LoginService"/>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!--配置事务的传播特性-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 哪些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allServiceMethod" expression="execution(* com.foraise.service.impl.*.*(..))"/>
<aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>