package quickstart.action;
import java.util.Collection;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import quickstart.model.Person;
import quickstart.service.PersonService;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Validateable;
import com.opensymphony.xwork2.ValidationAwareSupport;
@Results({
@Result(name="success", type="redirectAction", params = {"actionName" , "persons"})
})
public class PersonsAction extends ValidationAwareSupport implements ModelDriven<Object>, Validateable{
private static final long serialVersionUID = 1569168866929141867L;
private Person model = new Person();
private Integer id;
private Collection<Person> list;
@Autowired
private PersonService personService;
// GET /orders/1
public HttpHeaders show() {
return new DefaultHttpHeaders("show");
}
// GET /orders
public HttpHeaders index() {
list = personService.findAll();
return new DefaultHttpHeaders("index")
.disableCaching();
}
// GET /orders/1/edit
public String edit() {
return "edit";
}
// GET /orders/new
public String editNew() {
model = new Person();
return "editNew";
}
// GET /orders/1/deleteConfirm
public String deleteConfirm() {
return "deleteConfirm";
}
// DELETE /orders/1
public String destroy() {
personService.remove(id);
addActionMessage("Person removed successfully");
return "success";
}
// POST /orders
public HttpHeaders create() {
personService.save(model);
addActionMessage("New person created successfully");
return new DefaultHttpHeaders("success")
.setLocationId(model.getId());
}
// PUT /orders/1
public String update() {
personService.save(model);
addActionMessage("Order updated successfully");
return "success";
}
public void validate() {
if (model.getFirstName() == null || model.getFirstName().length() ==0) {
addFieldError("firstName", "The first name is empty");
}
if (model.getLastName() == null || model.getLastName().length() ==0) {
addFieldError("lastName", "The last name is empty");
}
}
public void setId(Integer id) {
if (id != null) {
this.model = personService.find(id);
}
this.id = id;
}
public Object getModel() {
return (list != null ? list : model);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
quickstart2.zip (30个子文件)
quickstart2
.project 856B
WebContent
WEB-INF
content
persons-deleteConfirm.jsp 566B
persons-index.jsp 783B
persons-edit.jsp 737B
persons-editNew.jsp 605B
persons-show.jsp 510B
applicationContext.xml 2KB
lib
web.xml 925B
contents
pages
welcome.html 264B
index.jsp 41B
META-INF
MANIFEST.MF 39B
src
quickstart
service
PersonService.java 1KB
action
PersonsAction.java 3KB
CommonSupport.java 261B
model
Person.java 822B
strutsExtension.xml 430B
struts.xml 677B
META-INF
persistence.xml 340B
.settings
org.eclipse.wst.common.project.facet.core.xml 229B
org.eclipse.jdt.core.prefs 330B
org.eclipse.jst.common.project.facet.core.prefs 62B
org.eclipse.wst.common.component 416B
build
classes
quickstart
service
PersonService.class 2KB
action
PersonsAction.class 3KB
CommonSupport.class 488B
model
Person.class 1KB
strutsExtension.xml 430B
struts.xml 677B
META-INF
persistence.xml 340B
.classpath 1KB
共 30 条
- 1
资源评论
- willowyxd2013-09-11还不错 不过和我想要的东西不一样
- oowwll2016-03-03还在学习中哦
- dingzhaobing2014-10-15资源不错,实用性不高好像
- codeDog~2012-08-08不错,正学习呢,很适合新手
码狂
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功