Struts2在body上请求PUT参数

时间:2016-03-04 04:13:13

标签: java struts2 httprequest restful-url

我想在身体上添加HTTP Request PUT的参数,但我只能这样做

http://localhost:9996/Events/employee/{id}.json?name={name}

那么如何将名字放在身上呢?

这是我的控制器

public class EmployeeController implements ModelDriven<Object>{
private static final long serialVersionUID = 1L;
private String id;
private String name;
private Object model;  
private EmployeeRepository employeeRepository = new EmployeeRepository();

//GET
public HttpHeaders index() { 
    model = employeeRepository.findAllEmployee(); 
    return new DefaultHttpHeaders("index").disableCaching();
}

// GET
public HttpHeaders show() { 
    model = employeeRepository.getEmployeeById(id);
    return new DefaultHttpHeaders("show").disableCaching();
}

//POST
public HttpHeaders create() { 
    Integer empId = Integer.parseInt(id);
    Employee emp = new Employee(empId, name, "PQR");
    employeeRepository.addEmployee(emp);
    model = employeeRepository.findAllEmployee();
    return new DefaultHttpHeaders("create").disableCaching();
}

//PUT
public HttpHeaders update() {  
    Integer empId = Integer.parseInt(id);
    Employee emp = new Employee(empId, name, "PQR");
    employeeRepository.updateEmployee(emp);
    model = employeeRepository.findAllEmployee();
    return new DefaultHttpHeaders("update").disableCaching();
}

//DELETE
public HttpHeaders destroy() {   
    employeeRepository.deleteEmployee(id); 
    model = employeeRepository.findAllEmployee();
    return new DefaultHttpHeaders("destroy").disableCaching();
}

public  String  getId()                 { return id; } 
public  void    setId(String id)        { this.id = id; } 
public  String  getName()               { return name; } 
public  void    setName(String name)    { this.name = name; } 
public  Object  getModel()              { return model; }

0 个答案:

没有答案