FastQuery 1.0.46 发布,更新如下:FastQuery支持JAX-RS注解,不需实现类,便能构建极简的RESTful.不得不简单的设计,可见一斑. @Path("userInfo")
public interface UserInfoDBService extends QueryRepository {
// 查询并实现分页
@Path("findAll")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Query(value = "select id,name,age from `userinfo` where 1", countField = "id")
Page<Map<String, Object>> findAll(@QueryParam("pageIndex") @PageIndex int pageIndex,
@QueryParam("pageSize") @PageSize int pageSize);
}没错, 不用去写任何实现类, 访问http://<your host>/rest/userInfo/findAll?pageIndex=1&pageSize=5, 就可以看到效果。 DB接口不仅能当做WEB Service,同时也是一个DB接口。 当然,如果不喜欢太简单,可以把DB接口注入到JAX-RS Resource类中: import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
@Path("hi")
public class Hi {
@Inject
private UserInfoDBService db;
@GET
@Produces({"text/html"})
public String hi() {
// use db...
return "hi";
}
}详细文档请参阅: |