HKINQ 2016-02-27 16:00 采纳率: 0%
浏览 1387

关于Struts2 DomainDriven

为何Struts2一直没有自动实例化域
代码如下:

jsp

 <%@ taglib prefix="s" uri="/struts-tags" %>
<%--
  Created by IntelliJ IDEA.
  User: 健勤
  Date: 2016/2/4
  Time: 15:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加员工</title>
</head>
<body>
    <s:form action="addEmpAction" method="POST">
      <s:textfield name="employee.name" label="员工名"/><br/>
      <s:textfield name="employee.password" label="员工密码"/><br/>
      <s:textfield name="employee.salary" label="工资"/><br/>
      <s:submit value="提交"/>
      <s:reset value="重置"/>
    </s:form>
</body>
</html>

Action

 package org.hrsystem.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.hrsystem.service.IMgrService;
import org.hrsystem.vo.Employee;

/**
 * Created by 健勤 on 2016/2/3.
 */
public class AddEmpAction extends ActionSupport {
    private IMgrService mgrService;
    private Employee employee;

    @Override
    public String execute() throws Exception {
        this.getActionMessages().clear();
        ActionContext actionContext = ActionContext.getContext();

        String mgrName = (String) actionContext.getSession().get("user");

        boolean flag = mgrService.addEmp(employee, mgrName);

        if(flag){
            addActionMessage("添加员工成功!");
        }
        else{
            addActionMessage("添加员工失败!");
        }

        return SUCCESS;
    }

    public IMgrService getMgrService() {
        return mgrService;
    }

    public void setMgrService(IMgrService mgrService) {
        this.mgrService = mgrService;
    }

    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }
}

domain

 package org.hrsystem.vo;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by 健勤 on 2016/2/2.
 */
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "employee_inf")
public class Employee {
    @Id
    @Column(name = "emp_id")
    @GenericGenerator(name = "employee_sequence",strategy = "sequence")
    @GeneratedValue(generator = "employee_sequence")
    private Integer id;
    @Column(name = "emp_name",nullable = false,unique = true, length = 30)
    private String name;
    @Column(name = "emp_password",nullable = false,length = 30)
    private String password;
    @Column(name = "emp_salary",nullable = false)
    private double salary;
    @OneToMany(targetEntity = Payment.class,mappedBy = "employee")
    private Set<Payment> payments = new HashSet<>();
    @ManyToOne(targetEntity = Manager.class)
    @JoinColumn(name = "mgr_id")
    private Manager manager;

    public Employee() {
    }

    public Employee(String name, String password, double salary, Set<Payment> payments, Manager manager) {
        this.name = name;
        this.password = password;
        this.salary = salary;
        this.payments = payments;
        this.manager = manager;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public Set<Payment> getPayments() {
        return payments;
    }

    public void setPayments(Set<Payment> payments) {
        this.payments = payments;
    }

    public Manager getManager() {
        return manager;
    }

    public void setManager(Manager manager) {
        this.manager = manager;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Employee)) return false;

        Employee employee = (Employee) o;

        if (name != null ? !name.equals(employee.name) : employee.name != null) return false;
        return !(password != null ? !password.equals(employee.password) : employee.password != null);

    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (password != null ? password.hashCode() : 0);
        return result;
    }
}

  • 写回答

2条回答 默认 最新

  • devmiao 2016-02-27 22:58
    关注
    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集