admin0_1 2019-06-13 23:09
浏览 306

消息 attempt to create saveOrUpdate event with null entity 一直报错这个快逼疯了

实体类
package com.user.bean;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="clas")
public class Student {

@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@Column(length=600,nullable=false)
private String name;
@Column(length=600,nullable=false)
private String desc;
@Column(length=600,nullable=false)
private String remark;

public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getClas() {
return name;
}
public void setClas(String clas) {
this.name = clas;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
}

dao里面
package com.user.dao.impl;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.user.bean.Student;
@Repository
public class IStudentDao extends HibernateDaoSupport implements com.user.dao.IStudentDao {
@Resource(name="sessionFactory")
public void setHibernateSessionFactroy(SessionFactory sessionFactory){
this.setSessionFactory(sessionFactory);
}

//添加分类
public void addStudent(Student student) {
// TODO Auto-generated method stub
this.getHibernateTemplate().save(student);

}
}

service里面

package com.user.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.user.dao.IStudentDao;
import com.user.bean.Student;
@Service
public class StudentService implements com.user.service.StudentService {
@Resource
private IStudentDao studentDao;

@Transactional(readOnly=false,propagation=Propagation.REQUIRED)
public void addStudent(Student student) {
// TODO Auto-generated method stub
studentDao.addStudent(student);

}
}

Action里面

package com.user.action;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.user.bean.Student;
import com.user.service.StudentService;

@Controller
@Scope("prototype")
public class StudentAction {
@Resource
private StudentService studentService;
private Student student;

//查询分类管理
public String list() {
return "list";
}
//到添加的页面
public String toAddpage() {

return "toAddpage";                                                                                                                                                                

}
//添加的方法
public String add() {
studentService.addStudent(student);
return "add";
}
}

jsp里面

<%--

action="${ pageContext.request.contextPath }/student_add.action" method="post">
                        <div class="am-form-group">
                            <label for="user-name" class="am-u-sm-3 am-form-label">
                                分类名称</label>
                            <div class="am-u-sm-9">
                                <input type="text" id="name" required
                                    placeholder="分类名称" name="student.name">
                                    <small>10字以内...</small>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="user-name" class="am-u-sm-3 am-form-label">
                                分类描述</label>
                            <div class="am-u-sm-9">
                                <input type="text" id="student.name" required
                                    placeholder="分类描述" name="student.desc">
                                    <small>10字以内...</small>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="user-intro" class="am-u-sm-3 am-form-label">
                                备注</label>
                            <div class="am-u-sm-9">
                                <textarea class="" rows="5" id="intro" name="student.remark"
                                    placeholder="输入备注"></textarea>
                                <small>250字以内...</small>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3">
                                <input type="submit" class="am-btn am-btn-success" value="添加分类" />
                                <a href="type.jsp"><input  class="am-btn am-btn-success" value="取消添加" /></a>
                            </div>
                        </div>
                    </form> --%>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 电脑最近经常蓝屏,求大家看看哪的问题
    • ¥60 高价有偿求java辅导。工程量较大,价格你定,联系确定辅导后将采纳你的答案。希望能给出完整详细代码,并能解释回答我关于代码的疑问疑问,代码要求如下,联系我会发文档
    • ¥50 C++五子棋AI程序编写
    • ¥30 求安卓设备利用一个typeC接口,同时实现向pc一边投屏一边上传数据的解决方案。
    • ¥15 SQL Server analysis services 服务安装失败
    • ¥15 基于面向对象的图书馆借阅管理系统
    • ¥15 opencv图像处理,需要四个处理结果图
    • ¥20 centos linux 7.9安装php8.2.18不支持mysqli模块的问题
    • ¥15 stata空间计量LM检验
    • ¥15 关于k8s node节点被释放后如何驱逐节点并添加新节点