<实践>Voldemort与Objot集成的WAP高性能方案与简单实现(三)
3、以User为例进行CRU操作
Id.java //Model的父类,为了该死的JSTL我得加上get/set
public abstract class Id<T extends Id<T>> {@EncDecpublic long id;public long id() {return id;}@SuppressWarnings("unchecked")public T id(long id_) {id = id_;return (T)this;}public long getId() {return id;}public void setId(long id) {this.id = id;}}
public class User extends Id<User> {@EncDecpublic String name;@EncDecpublic int age;public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}}
public class DoUser extends Do {@Service@Transaction.Any //只是跳转用,没有数据操作public String create_() throws Exception {return "/create";}@Servicepublic String create(String name, int age) throws Exception {User u = new User();u.name = name;u.age = age;data.put(u);return "redirect:/";}@Service@Transaction.Anypublic String update_(long id, ModelMap map) throws Exception {User u = data.get(User.class, id);map.put("user", u);return "/update";}@Servicepublic String update(long id, String name, int age) throws Exception {User u = new User().id(id);u.name = name;u.age = age;data.put(u);return "redirect:/";}@Servicepublic String get(long id, ModelMap map) throws Exception {User u = data.get(User.class, id);map.put("user", u);return "/index";}}