save失败 但是不报错!顺便问下 在action中怎么注入servicepublic ModelAndView save(HttpServletRequest request,
HttpServletResponse response)throws Exception{
//menuSer.queryS();
smenuService = (MenuService) getWebApplicationContext().getBean("menuService");
smenuService.save();
return new ModelAndView("menu_jsp/menu");
}public void save() {
// TODO Auto-generated method stub
smenuDao.save();
}
public void save() {
// TODO Auto-generated method stub
Menu m1 = new Menu();
Menu m2 = new Menu();
Menu m3 = new Menu();
Menu m4 = new Menu();
m1.setName("百度");m1.setUrl("http://www.baidu.com");
m2.setName("搜狐");m2.setUrl("http://www.souhu.com");
m3.setName("人人");m3.setUrl("http://www.renren.com");
m4.setName("谷歌");m4.setUrl("http://www.google.com");
//EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa_test");
//System.out.println(emf.createEntityManager().getTransaction().notify().....isActive()==true);
//emf.createEntityManager().getTransaction().begin();
this.getJpaTemplate().persist(m1);
this.getJpaTemplate().persist(m2);
this.getJpaTemplate().persist(m3);
this.getJpaTemplate().persist(m4);
//emf.createEntityManager().getTransaction().commit();
} <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="change*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="beanNameAutoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*DaoImp</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<!-- 直接使用Spring的 JpaTemplate -->
<bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="menuDao" class="com.wujw.springMVC.dao.MenuDaoImp">
</bean>
<bean id="menuService" class="com.wujw.springMVC.service.MenuServieImp">
<property name="smenuDao" ref="menuDao"></property>
</bean>
<bean id="menuAction" class="com.wujw.springMVC.action.MenuAction">
<property name="smenuService" ref="menuService"></property>
</bean>
HttpServletResponse response)throws Exception{
//menuSer.queryS();
smenuService = (MenuService) getWebApplicationContext().getBean("menuService");
smenuService.save();
return new ModelAndView("menu_jsp/menu");
}public void save() {
// TODO Auto-generated method stub
smenuDao.save();
}
public void save() {
// TODO Auto-generated method stub
Menu m1 = new Menu();
Menu m2 = new Menu();
Menu m3 = new Menu();
Menu m4 = new Menu();
m1.setName("百度");m1.setUrl("http://www.baidu.com");
m2.setName("搜狐");m2.setUrl("http://www.souhu.com");
m3.setName("人人");m3.setUrl("http://www.renren.com");
m4.setName("谷歌");m4.setUrl("http://www.google.com");
//EntityManagerFactory emf = Persistence.createEntityManagerFactory("jpa_test");
//System.out.println(emf.createEntityManager().getTransaction().notify().....isActive()==true);
//emf.createEntityManager().getTransaction().begin();
this.getJpaTemplate().persist(m1);
this.getJpaTemplate().persist(m2);
this.getJpaTemplate().persist(m3);
this.getJpaTemplate().persist(m4);
//emf.createEntityManager().getTransaction().commit();
} <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref local="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED</prop>
<prop key="add*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="remove*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="change*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="beanNameAutoProxyCreator"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*DaoImp</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<!-- 直接使用Spring的 JpaTemplate -->
<bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="menuDao" class="com.wujw.springMVC.dao.MenuDaoImp">
</bean>
<bean id="menuService" class="com.wujw.springMVC.service.MenuServieImp">
<property name="smenuDao" ref="menuDao"></property>
</bean>
<bean id="menuAction" class="com.wujw.springMVC.action.MenuAction">
<property name="smenuService" ref="menuService"></property>
</bean>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货