EWeb4J 框架迁移到 GitHub
程序员文章站
2022-06-08 12:50:51
...
- 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更新:
<?xml version="1.0" encoding="UTF-8"?> <beans> <eweb4j> <reload>0</reload> <debug>1</debug> <locales> <locale language="zh" country="CN"/> </locales> <properties> <file id="" path="" global="false"/> </properties> <ioc> <open>true</open> <logs> <log console="0" level="info" file="logs/logs.log" size="5"/> </logs> <iocXmlFiles> <path></path> </iocXmlFiles> </ioc> <orm> <open>1</open> <logs> <log console="1" level="info" file="logs/logs.log" size="5"/> </logs> <dataSource>com.mchange.v2.c3p0.ComboPooledDataSource</dataSource> <scanPojoPackage> <path>.</path> </scanPojoPackage> <ormXmlFiles> <path></path> </ormXmlFiles> <dbInfoXmlFiles> <path>mysql.xml</path> </dbInfoXmlFiles> </orm> <mvc> <open>true</open> <logs> <log console="1" level="info" file="logs/logs.log" size="5"/> </logs> <upload tmp="${RootPath}/WEB-INF/tmp" maxMemorySize="20M" maxRequestSize="20M" /> <scanActionPackage> <path>.</path> </scanActionPackage> <scanInterceptorPackage> <path>.</path> </scanInterceptorPackage> <actionXmlFiles> <path></path> </actionXmlFiles> <interXmlFiles> <path></path> </interXmlFiles> </mvc> </eweb4j> </beans>
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 List<Pet> pets = new ArrayList<Pet>(); /* 购买记录 */ @OneToMany private List<PurchaseRecord> purchaseRecords = new ArrayList<PurchaseRecord>(); /* 购物车 */ @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 }
上一篇: Play framework 国际化
下一篇: php中的ini