SSH整合,增删查改,就增加不成功,帮忙看下i
applicationcontext.xml:
...
<bean id="userAction" class="com.integration.action.UserAction">
<property name="userService" ref="userService"></property>
</bean>
...
struts.xml:
<action name="user" class="userAction">
<result name="success" type="redirect"> /userquery.action</result>
</action>
com.integration.action.UserAction:
package com.integration.action;
import com.integration.entity.User;
import com.integration.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private UserService userService;
public void setUserService(UserService userService)
{
this.userService=userService;
}
private User user;
public String excute()
{
User u=new User();
//u.setId(user.getId());
u.setName(user.getName());
u.setPassword(user.getPassword());
u.setType(user.getType());
userService.savaUser(u);//保存到数据库
return SUCCESS;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
service sava实现:
public void savaUser(User user) {
// TODO Auto-generated method stub
if(userDAO.findById(user.getId())==null)
userDAO.sava(user);
}
dao层实现:
public class UserDAOImpl extends HibernateDaoSupport implements UserDAO {
//private SessionFactory sessionFactory;
//HibernateTemplate hibernatetemplate;
public void sava(User user)
{
//this
this.getHibernateTemplate().save(user);
}
JSP页面:
<body>
<center>
<s:form action="user" method="post">
<tr>
<td colspan="2" align="center">
<h1><s:text name="欢迎注册"></s:text></h1>
<s:property value="exception.message"></s:property>
</td>
</tr>
<s:textfield name="user.name" key="用户名" tooltip="enter your name" required="ture" />
<s:password name="user.password" key="密码" tooltip="enter your password" required="ture" />
<s:textfield name="user.type" key="类型" tooltip="enter your type" required="ture" />
<s:submit value="提交"/>
</s:form>
</center>
</body>
每次注册的时候 操作台不会显示hibernet关于insert的sql语句,应该是没有触发save
不知道哪里出错,其他删改查都能实现并打印在操作台
------解决方案--------------------什么异常?没有报错?这个自己应该可以找出啊
------解决方案--------------------看你新增的时候主键注释掉了,是不是这个原因??
------解决方案--------------------(其他都行)那你肯定没有事务提交啊
------解决方案--------------------查询是不需要事务的。
------解决方案--------------------你的操作不需要配置事务。在检查代码。。绝对是代码有纰漏,加油