在页面里点喂食时,本来是体力增加30的,但后来用后置通知,再做一些业务,就是体力少于200的直接增长到200,大于200的再加50,但我的不起作用。请各位大侠帮个忙看一下,万分感谢
通知代码:public class LotteryAdvice implements AfterReturningAdvice {
private PetInfoDAO petInfoDao;
public void setPetInfoDao(PetInfoDAO petInfoDao) {
this.petInfoDao = petInfoDao;
}
public void afterReturning(Object returnValue, Method method, Object[] args,
Object target) throws Throwable {
if(method.getName().equals("updateStrengthCuteGame"))
{
int petId = (Integer)args[0];
PetInfo petInfo = (PetInfo)petInfoDao.findById(petId);
if(petInfo.getPetStrength()<200)
{
petInfo.setPetStrength(200);
petInfoDao.updateStrengthCuteGame(petInfo);
System.out.println("吃到菠菜,体力增长到200!");
}
else
{
petInfo.setPetStrength(petInfo.getPetStrength()+50);
petInfoDao.updateStrengthCuteGame(petInfo);
System.out.println("吃到菠菜,体力增长50");
}
}
}
}spring的配置文件:<?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"
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-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<!-- 事务 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="*" propagation="REQUIRED" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:pointcut expression="execution(* com.guangri.dao.impl.hibernate.*.*(..))" id="daoMethods"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="daoMethods"/>
</aop:config>
 
 <bean id="petInfoDAO" class="com.guangri.dao.impl.hibernate.PetInfoDAO">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>  <bean id="lotteryAdvice" class="com.guangri.biz.impl.LotteryAdvice">
  <property name="petInfoDao" ref="petInfoDAO"></property>
 </bean>  <bean id="petInfoBiz" class="org.springframework.aop.framework.ProxyFactoryBean">
  <property name="proxyInterfaces">
  <value>com.guangri.dao.Pet</value>
  </property>
  <property name="interceptorNames">
  <list><value>lotteryAdvice</value></list>
  </property>
  <property name="target" ref="petInfoDAO"></property>
 </bean>
 
 <bean name="/login" class="com.guangri.actions.PetAction">
  <property name="petInfoDAO" ref="petInfoDAO"></property>
 </bean>
</beans>struts的action类public void doFeed(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)
{
ShowForm showForm = (ShowForm)form;
int petId = showForm.getPetInfo().getPetId();
PetInfo petInfo = petInfoDAO.findById(petId);
petInfo.setPetStrength(petInfo.getPetStrength()+30);
petInfoDAO.updateStrengthCuteGame(petInfo);
}daoimpl层public class PetInfoDAO extends HibernateDaoSupport implements Pet{
public void updateStrengthCuteGame(PetInfo petInfo) {
getHibernateTemplate().update(petInfo);
}
}
dao层接口
[code=Java]
public interface Pet {
public void updateStrengthCuteGame(PetInfo petInfo);
}[/code]