web.xml配置
applicationContext.xml
package ssh.test.struts2.action;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ssh.test.struts2.action.model.Test;
import ssh.test.struts2.action.model.TestDAO;
@Service("ser")
public class ser
{
@Autowired
user user;
@Autowired
TestDAO testDAO;
@Autowired
Test test;
public Test getTest() {
return test;
}
public void setTest(Test test) {
this.test = test;
}
public TestDAO getTestDAO() {
return testDAO;
}
public void setTestDAO(TestDAO testDAO) {
this.testDAO = testDAO;
}
public user getUser() {
return user;
}
public void setUser(user user) {
this.user = user;
}
@Transactional
public void s()
{
user.setAge("aaa");
/*Session se = testDAO.getCurrentSession();
Transaction t = se.getTransaction();
t.begin();
test.setId(1);
test.setName("aa");
testDAO.save(test);
t.commit();
se.flush();
se.close();*/
test.setId(1);
test.setName("aa");
testDAO.save(test);
}
}
package ssh.test.struts2.action;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import ssh.test.struts2.action.model.Test;
import ssh.test.struts2.action.model.TestDAO;
import org.apache.struts2.convention.annotation.*;
import com.opensymphony.xwork2.ActionSupport;
@Namespace("/user")
@Results({@Result(name = "success", location = "/index.jsp"),@Result(name = "error", location = "/error.jsp")})
@Transactional
public class UserAction
{
@Autowired
ser ser;
public ser getSer() {
return ser;
}
public void setSer(ser ser) {
this.ser = ser;
}
@Action("aa")
public String aa()
{
ser.s();
//System.out.println(user.getAge());
return "error";
}
}
包结构:
运行到时可要,就是数据库数据插不了
applicationContext.xml
package ssh.test.struts2.action;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ssh.test.struts2.action.model.Test;
import ssh.test.struts2.action.model.TestDAO;
@Service("ser")
public class ser
{
@Autowired
user user;
@Autowired
TestDAO testDAO;
@Autowired
Test test;
public Test getTest() {
return test;
}
public void setTest(Test test) {
this.test = test;
}
public TestDAO getTestDAO() {
return testDAO;
}
public void setTestDAO(TestDAO testDAO) {
this.testDAO = testDAO;
}
public user getUser() {
return user;
}
public void setUser(user user) {
this.user = user;
}
@Transactional
public void s()
{
user.setAge("aaa");
/*Session se = testDAO.getCurrentSession();
Transaction t = se.getTransaction();
t.begin();
test.setId(1);
test.setName("aa");
testDAO.save(test);
t.commit();
se.flush();
se.close();*/
test.setId(1);
test.setName("aa");
testDAO.save(test);
}
}
package ssh.test.struts2.action;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import ssh.test.struts2.action.model.Test;
import ssh.test.struts2.action.model.TestDAO;
import org.apache.struts2.convention.annotation.*;
import com.opensymphony.xwork2.ActionSupport;
@Namespace("/user")
@Results({@Result(name = "success", location = "/index.jsp"),@Result(name = "error", location = "/error.jsp")})
@Transactional
public class UserAction
{
@Autowired
ser ser;
public ser getSer() {
return ser;
}
public void setSer(ser ser) {
this.ser = ser;
}
@Action("aa")
public String aa()
{
ser.s();
//System.out.println(user.getAge());
return "error";
}
}
包结构:
运行到时可要,就是数据库数据插不了