日期:2014-05-17 浏览次数:20910 次
package com.xxb.assetsmanage.action; import java.util.List; import javax.annotation.Resource; import org.springframework.stereotype.Component; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; import com.xxb.assetsmanage.model.User; import com.xxb.assetsmanage.service.UserService; @Component("userAction") public class UserAction extends ActionSupport implements ModelDriven<User> { private boolean success; private User user; private UserService userService; public boolean isSuccess() { return success; } public void setSuccess(boolean success) { this.success = success; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public UserService getUserService() { return userService; } @Resource public void setUserService(UserService userService) { this.userService = userService; } public User getModel() { return user; } @Override public String execute() throws Exception { List<User> users = userService.isLogin(user); System.out.println(users.size()); if (users.size() > 0) { success = true; } else { success = false; } return SUCCESS; } public String add(User user) { userService.add(user); return "addsuccess"; } public String del(User user) { userService.del(user); return "delsuccess"; } public String mod(User user) { userService.mod(user); return "modsuccess"; } } 实体类 package com.xxb.assetsmanage.model; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Table; @Entity @Table(name="t_user") public class User { private int id; private String name; private String password; private Set<Assets> assetses = new HashSet<Assets>(); @OneToMany(mappedBy="user",cascade={CascadeType.ALL}) public Set<Assets> getAssetses() { return assetses; } public void setAssetses(Set<Assets> assetses) { this.assetses = assetses; } @Id @GeneratedValue public int getId() { return id; } public void setId(int 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; } }
<package name="listjson" extends="json-default"> <action name="projectjson" class="projectListAction"> <result type="json"> <param name="includeProperties"> success, totalSize, projects\[\d+\]\.id, projects\[\d+\]\.name </param> </result> </action> <action name="useraction" class="userAction"> <result type="json"> <param name="includeProperties"> success