- EWeb4J 框架: https://github.com/laiweiwei/eweb4j-framework
- EWeb4J Demo Petstore : https://github.com/laiweiwei/eweb4j-petstore
- EWeb4J Demo SolidBase: https://github.com/laiweiwei/eweb4j-solidbase
- EWeb4J Demo SolidBase-webapp:https://github.com/laiweiwei/solidbase-webapp
看看最新版本EWeb4J-1.9的start.xml更新:
0 1 true 1 com.mchange.v2.c3p0.ComboPooledDataSource . mysql.xml true . .
SolidBase 跟 在线演示的一样是最新的。
Petstore 完全采用最新版本 EWeb4J-1.9 开发。大家可以看看它的代码,这里贴上几个哈:
/** * 登录鉴权 * @author weiwei * */ @Interceptor(method = "check", priority = 0, uri = { @Uri(type = "start", value = "members/") }, except = {"members/login", "members/signup"}) @Singleton public class LoginAuth { public String check(){ Member member = (Member)MVC.ctx().getSession().getAttribute(Const.LOGIN_ATTR); if (member == null){ return "action:"; } return null; } }
public class MembersControl { private Member member; @Validate({"member.user.name", "member.user.passcode", "member.name"}) @Transactional public Object create(Validation val){ Map message = new HashMap(); if (val.hasErr()){ message.put("status", false); message.put("message", val.getAllErr()); return message; } message.put("status", member.signup()); return message; } @Validate({"member.user.name", "member.user.passcode"}) public Object doLoginAtPut(Validation val){ Map message = new HashMap(); if (val.hasErr()){ message.put("status", false); message.put("message", val.getAllErr()); return message; } try{ Member loginMember = member.login(); if (loginMember != null){ message.put("status", true); MVC.ctx().getSession().setAttribute(Const.LOGIN_ATTR, loginMember); }else{ message.put("status", false); } }catch(Exception e){ message.put("status", false); } return message; } public Map doLogoutAtPut(){ Map message = new HashMap(); message.put("status", true); MVC.ctx().getSession().removeAttribute(Const.LOGIN_ATTR); return message; } public String doHomeAtGet(){ return "欢迎" + MVC.ctx().getModel().get(Const.LOGIN_ATTR) + "访问会员中心"; } public void setMember(Member member) { this.member = member; } }
/** * 宠物商店会员 模型 * * @author weiwei * */ @Entity @Table(name = "t_member") public class Member extends Model { /* 会员名字 */ @Column(unique=true) @Required @Chinese private String name; /* 性别 0 保密 1 男 2 女 */ private int gender; /* 年龄 */ @Int @Size(min=1, max=99) private int age; /* 所持金币数 */ @Column(name="gold_coins") @Int @Size(min=1, max=9999999) private long goldCoins; /* 登陆账户 */ @OneToOne private User user; /* 注册时间 */ @Column(name="create_at") private Date createAt; /* 所拥有的宠物 */ @OneToMany private Listpets = new ArrayList (); /* 购买记录 */ @OneToMany private List purchaseRecords = new ArrayList (); /* 购物车 */ @OneToOne private Cart cart; public boolean signup(){ this.createAt = new Date(); this.cart = new Cart(); this.cart.create("description"); this.user.create("name", "passcode"); return this.create("name","user", "createAt", "cart"); } public Member login(){ if (this.user.login()) return find("byUser", user.getId()).first(); return null; } //setter and getter }