经过奋战,终于有个稳定点的SNAPSHOT版本咯。
较之上个版本1.8.6,本版本1.9-SNAPSHOT有以下几个更新点:
<%@ page contentType="text/html; charset=utf-8" language="java" pageEncoding="utf-8"%>
<div class="accordion" fillSpace="sideBar">
<jsp:include page="/${switchEnvPath}"></jsp:include>
</div>
这样目标xxx.jsp/xxx.html页面是从WebContent中开始寻找并且被包含进来。并且因为这里已经包裹了这段代码:
<div class="accordion" fillSpace="sideBar"> </div>
因此在xxx.jsp/xxx.html中已经不再需要包裹上面这段代码了。
eweb4j 框架更新了比较多。详细看看下面列表
| HTTP Method | URI | Class.Method | Params |
| GET | /demo | DemoControl.index | |
| POST | /demo | DemoControl.create | |
| PUT | /demo/{id} | DemoControl.update | id={id} |
| DELETE | /demo/{id} | DemoControl.destroy | id={id} |
| GET | /demo/{id} | DemoControl.show | id={id} |
| GET | /demo/{id}/edit | DemoControl.edit | id={id} |
| GET | /demo/new | DemoControl.editNew | id={id} |
return "action:xxx@PUT?name=weiwei&age=5";
//符号@只能出现一次,框架不再采用response.sendRedirect的方式来处理,而是构建一个
form表单:
<form id="form_id" action="xxx" method="post">
<input type="hidden" name="_method" value="PUT" />
<input name="name" value="weiwei" />
<input name="age" value="5" />
<input type="submit" />
</form>
<script>document.getElementById('form_id').submit();</script>
然后使用response.getWriter().print打印上面这段内容,从而实现模拟客户端的请求,这样就支持GET之外的请求了,还可以带参数。
PS:如果指定的Action依然是GET的,则会采用redirect的方式执行,而不是表单的形式
其中每个的意义是:
do:一直到Bind或者At为止的单词都会被解析为 URI
Bind:一直到At或者末尾为止的单词都会被解析为URI中的变量部分/{param1}/{param2}(多个arg用And连接)
Join:一定要跟在Bind之后,例如 doHelloBindNameJoinWorldAtGet = /hello/{name}/world GET
At:一直到末尾为止的单词都会被解析为Http Method(多个method用 Or 连接)
For Example1:
public void doRemoveBindIdAtDelete(int id){}
解析后:
uri => remove/{id}
http => DELETE
访问例子:
DELETE /remove/3
For Example2:
private String name;
public void setName(String name){this.name = name}
public void doHelloBindNameAtGet(){}
解析后:
uri => hello/{name}
http => GET
访问例子:
DELETE /hello/weiwei
For Example3:
public class PetsControl{
public String doBindIdJoinEditAtGet(int id){
return "fmt:pets/view/edit.html";
}
}
解析后:
uri => pets/{id}/edit
http => GET
访问例子:
GET /pets/3/edit
public String doHelloAtPost(@QueryParam("user") final User user, Map model) {
List<User> list = new ArrayList<User>();
list.add(user);
list.add(new User());
model.put("pojos", list);
return "fmt:pet/view/fmt-list.html";
}
fmt-list.html
<#list pojos as user>
<p>${user.name}-${user.age}</p>
</#list>
例子二
public String doTestAtGet() {
return "action:pet/hello@POST?user.name=微微&user.age=23";
}
@Result(name = { "success" }, type = { "fmt" }, value = { "index.html" })
public String doIndexAtGet(Map model) {
model.put("message", "Hello FreeMarker!");
return "success";
}
index.html
<h1>${message}</h1>
@Entity
@Table(name="t_pet")
public class Pet extends Model{
public final static Pet instance = new Pet();
private String name;
private int age;
public Pet(){}
public Pet(String name, int age){
this.name = name;
this.age = age;
}
//setter and getter
}
//使用
new Pet("xiaohei", 5).create();//insert
new Pet("xiaohei", 5).save();//当没有ID值的时候是insert
Pet pet = new Pet("xiaobai",4);
pet.create();//insert这时候pet.id已经被注入了
pet.setName("test");
pet.save();//这时候因为pet.id有值,所以是update
pet = new Pet();
pet.setId(2);
pet.load();//这个时候会通过id值去查询数据库,并将数据注入到pet实例中。
List<Pet> pets = Pet.instance.findAll();
/* 分页 */
List<Pet> page = Pet.instance.find().fetch(10);
page = Pet.instance.find().fetch(2, 5);
/* 条件查询 */
List<Pet> pets = Pet.instance.find("byName", "xiaohei").fetch();
pets = Pet.instance.find("byNameAndAge", "xiaohei", 5).fietch();
pets = Pet.instance.find("name = ?", "xiaohei").fetch();
Pet p = Pet.instance.find("name = ?", "xiaohei").first();
p = Pet.instance.findById(3);
p = Pet.instance.find("byNameAndAge", "xiaohei", 5).first();
/* 删除 */
Pet.instance.delete("byName", "xiaohei");
Pet.instance.deleteAll();
/* 计算 */
long rows = Pet.instance.count();/* select count(*) */
rows = Pet.instance.count("byName", "xiaohei");/* count(*) ... where name='xoapjeo' */
[*] 待续