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
    关注
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料