日期:2014-05-18  浏览次数:20804 次

SSH整合,DAO层save失效
我刚整合SSH 想试试一个小例子 结果调了半天还是出错。希望大家帮我看看~

login.JSP 表单post到 StudentAction
 <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";
}
}


这里说明一下,System.out.println是为了测试数据有没有传过来 结果证明传过来了

StudentService:

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;
}

}


StudentDAO里面我加了一句 我怀疑是save方法有问题  我在save方法后面print一下

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