日期:2014-05-18 浏览次数:20804 次
<form action="StudentAction.action" method="post">
姓名:<input type="text" name="name"/><br>
年龄:<input type="text" name="age"/><br>
成绩:<input type="text" name="score"/><br>
<input type="submit" value="提交">
</form>
package action;
import java.util.List;
import model.Student;
import service.StudentService;
public class StudentAction
{
private StudentService studentService;
private String name;
private Integer age;
private Integer score;
private List studentList;
/*set get method 省略*/
public String execute() throws Exception
{
Student student =new Student();
student.setName(name);
student.setScore(score);
student.setAge(age);
if(name==null)
{System.out.println("NAME NULL!");}
else
{System.out.println(""+student.getName()+student.getAge()+student.getScore());}
studentService.getStudentDao().save(student);
//studentList=studentService.getStudentDao().findAll();
System.out.println("Action!");
//System.out.println(studentList.size());
return "success";
}
}
package service;
import dao.StudentDAO;
public class StudentService
{
private StudentDAO studentDao;
public void save(){
}
public StudentDAO getStudentDao() {
return studentDao;
}
public void setStudentDao(StudentDAO studentDao)
{
this.studentDao = studentDao;
}
}
package dao;
import java.util.List;
import model.Student;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class StudentDAO extends HibernateDaoSupport {
private static final Logger log = LoggerFactory.getLogger(StudentDAO.class);
//property constants
public static final String NAME = "name";
public static final String AGE = "age";
public static final String SCORE = "score";
protected void initDao() {
//do nothing
}
public void save(Student transientInstance) {
log.debug("saving Student instance");
try&nb