diff --git a/article_regain.html b/article_regain.html
index ebdd8b809..3df73e6aa 100644
--- a/article_regain.html
+++ b/article_regain.html
@@ -44,8 +44,8 @@
@Resource
private OrderService service;
- @WebMapping(url = "/order/find", comment = "查询单个订单")
- @WebParam(name = "#", type = long.class, comment = "订单ID")
+ @HttpMapping(url = "/order/find", comment = "查询单个订单")
+ @HttpParam(name = "#", type = long.class, comment = "订单ID")
public void logout(HttpRequest req, HttpResponse resp) throws IOException {
long orderid = req.getRequstURILastPath(0L);
resp.finishJson(service.findOrder(orderid));
diff --git a/convert.html b/convert.html
index d0acdcfbd..a43277dd6 100644
--- a/convert.html
+++ b/convert.html
@@ -181,7 +181,7 @@
// 获取他人基本信息
@AuthIgnore
- @WebMapping(url = "/user/info/")
+ @HttpMapping(url = "/user/info/")
public void info(HttpRequest req, HttpResponse resp) throws IOException {
int userid = Integer.parseInt(req.getRequstURILastPath());
UserSimpleInfo user = service.findUserInfo(userid);
@@ -189,7 +189,7 @@
}
//获取用户自己的信息
- @WebMapping(url = "/user/myinfo")
+ @HttpMapping(url = "/user/myinfo")
public void mydetail(HttpRequest req, HttpResponse resp) throws IOException {
int userid = currentUser(req).getUserid(); //获取当前用户ID
UserSimpleInfo user = service.findUserInfo(userid);
diff --git a/net.html b/net.html
index 146bcb459..98336a1a1 100644
--- a/net.html
+++ b/net.html
@@ -111,10 +111,10 @@
//登录操作
@AuthIgnore //登录操作不要判断登录态,所以需要标记为@AuthIgnore,不会调用 BaseSerlvet.authenticate 方法
- //因为WebMapping的判断规则用的是String.startsWith,所以WebMapping.url不能用正则表达式,只能是getRequestURI的前缀
- //且同一个HttpServlet类内的所有WebMapping不能存在包含关系, 如 /user/myinfo 和 /user/myinforecord 不能存在同一HttpServlet中。
- @WebMapping(url = "/user/login", comment = "用户登录")
- @WebParam(name = "bean", type = LoginBean.class, comment = "登录参数对象")
+ //因为HttpMapping的判断规则用的是String.startsWith,所以HttpMapping.url不能用正则表达式,只能是getRequestURI的前缀
+ //且同一个HttpServlet类内的所有HttpMapping不能存在包含关系, 如 /user/myinfo 和 /user/myinforecord 不能存在同一HttpServlet中。
+ @HttpMapping(url = "/user/login", comment = "用户登录")
+ @HttpParam(name = "bean", type = LoginBean.class, comment = "登录参数对象")
public void login(HttpRequest req, HttpResponse resp) throws IOException {
LoginBean bean = req.getJsonParameter(LoginBean.class, "bean"); //获取参数
RetResult<UserInfo> result = service.login(bean); //登录操作, service内部判断bean的合法性
@@ -123,7 +123,7 @@
//获取当前用户信息
//未登录的请求会被BaseSerlvet.authenticate方法拦截,因此能进入该方法说明用户态存在
- @WebMapping(url = "/user/myinfo", comment = "获取当前用户信息")
+ @HttpMapping(url = "/user/myinfo", comment = "获取当前用户信息")
public void myinfo(HttpRequest req, HttpResponse resp) throws IOException {
UserInfo user = service.current(req.getSessionid(false));
//或者使用 user = req.getAttribute("_current_userinfo"); 因为BaseSerlvet.authenticate方法已经将UserInfo注入到_current_userinfo属性中
@@ -132,19 +132,19 @@
//获取指定用户ID的用户信息, 请求如: /user/username/43565443
@AuthIgnore
- // 默认缓存时间是15秒,HttpBaseServlet会将每个进入该方法的请求的响应结果缓存15秒,缓存命中时不会再进入该方法,过期会清空。
+ // 默认缓存时间是15秒,HttpServlet会将每个进入该方法的请求的响应结果缓存15秒,缓存命中时不会再进入该方法,过期会清空。
// @HttpCacheable 必须配合 @AuthIgnore 使用, 因为跟当前用户有关的请求一般不适合所有用户请求。
// 翻页查询想缓存就需要将翻页信息带进url: /user/query/page:2/size:50 。
@HttpCacheable(seconds = 30) //有效期30秒
- @WebMapping(url = "/user/userinfo/", comment = "获取指定用户ID的用户信息")
- @WebParam(name = "#", type = int.class, comment = "用户ID")
+ @HttpMapping(url = "/user/userinfo/", comment = "获取指定用户ID的用户信息")
+ @HttpParam(name = "#", type = int.class, comment = "用户ID")
public void userinfo(HttpRequest req, HttpResponse resp) throws IOException {
UserInfo user = service.findUserInfo(Integer.parseInt(req.getRequstURILastPath()));
resp.finishJson(user); //输出用户信息
}
//更新个人头像
- @WebMapping(url = "/user/updateface", comment = "更新用户头像")
+ @HttpMapping(url = "/user/updateface", comment = "更新用户头像")
public void updateface(HttpRequest req, HttpResponse resp) throws IOException {
UserInfo user = service.current(req.getSessionid(false));
for (MultiPart part : req.multiParts()) { //遍历上传文件列表
@@ -170,8 +170,8 @@
API Doc
- 在小型互联网公司里,基本是追求敏捷开发,很少先花时间设计接口文档再进行开发,通常都是直接进行数据库设计和开发,开发完后需要开发人员需要编写接口文档提供给前端人员开发。为了减少文档的编写工作量和强制开发人员对接口进行注释,Redkale提供了apidoc命令,apidoc遍历当前进程中所有标记@WebServlet的可用HttpServlet,根据Servlet中@WebMapping、@WebParam生成json对象并输出文件。在系统运行时执行apidoc命令会在进程根目录下生成apidoc.json、apidoc.html文件。apidoc.html的模板可以定制, 只需在conf/目录下存放一个 apidoc-template.html 文件,且文件中必须包含关键字 ${content} 即可实现接口文档的自定义。
- 为了能正确显示接口文档,开发人员需要在编写HttpServlet时,在每个@WebMapping方法上加上comment属性和@WebParam注解, 一个方法上可以注解多个@WebParam, 如上面的 UserServlet 。RestHttpServlet是由RestService自动生成,@WebMapping、@WebParam在REST组件中存在对应的注解@RestMapping、@RestParam,因此在编写RestService时需要加上@RestMapping、@RestParam且加上comment属性。如范例: HelloService 。
+
在小型互联网公司里,基本是追求敏捷开发,很少先花时间设计接口文档再进行开发,通常都是直接进行数据库设计和开发,开发完后需要开发人员需要编写接口文档提供给前端人员开发。为了减少文档的编写工作量和强制开发人员对接口进行注释,Redkale提供了apidoc命令,apidoc遍历当前进程中所有标记@WebServlet的可用HttpServlet,根据Servlet中@HttpMapping、@HttpParam生成json对象并输出文件。在系统运行时执行apidoc命令会在进程根目录下生成apidoc.json、apidoc.html文件。apidoc.html的模板可以定制, 只需在conf/目录下存放一个 apidoc-template.html 文件,且文件中必须包含关键字 ${content} 即可实现接口文档的自定义。
+ 为了能正确显示接口文档,开发人员需要在编写HttpServlet时,在每个@HttpMapping方法上加上comment属性和@HttpParam注解, 一个方法上可以注解多个@HttpParam, 如上面的 UserServlet 。RestServlet是由RestService自动生成,@HttpMapping、@HttpParam在REST组件中存在对应的注解@RestMapping、@RestParam,因此在编写RestService时需要加上@RestMapping、@RestParam且加上comment属性。如范例: HelloService 。
WebSokcet 服务
diff --git a/plugin_rest.html b/plugin_rest.html index 61aab6d42..6fcf06be7 100644 --- a/plugin_rest.html +++ b/plugin_rest.html @@ -44,7 +44,7 @@ <server protocol="HTTP" port="6060" interceptor="org.redkalex.rest.RestNodeInterceptor"> <!-- REST的核心配置项 - base: REST服务的BaseServlet,必须是 org.redkalex.rest.RestHttpServlet 的子类,该属性值没有默认值,必须指定。 + base: REST服务的BaseServlet,必须是 org.redkalex.rest.RestServlet 的子类,该属性值没有默认值,必须指定。 autoload:默认值"true" 默认值. 加载当前server所能使用的Servce对象; mustsign:默认值"true" 是否只加载标记为RestController的Service类,默认加载所有可用Service includes:当autoload="true", 拉取类名与includes中的正则表达式匹配的类, 多个正则表达式用分号;隔开 @@ -61,9 +61,9 @@ </application>
- 通常配置都需要编写一个 org.redkalex.rest.RestHttpServlet 子类,主要用于获取当前用户信息和鉴权,且必须指定具体的User对象类。开发者的实现类可以参考 redkale-demo 中的BaseServlet类,以下是一个简单的范例:
+ 通常配置都需要编写一个 org.redkalex.rest.RestServlet 子类,主要用于获取当前用户信息和鉴权,且必须指定具体的User对象类。开发者的实现类可以参考 redkale-demo 中的BaseServlet类,以下是一个简单的范例:
public class SimpleRestServlet extends RestHttpServlet<UserInfo> {
+ public class SimpleRestServlet extends RestServlet<UserInfo> {
protected static final RetResult RET_UNLOGIN = RetCodes.retResult(RetCodes.RET_USER_UNLOGIN);
@@ -99,7 +99,7 @@
- 编写完 org.redkalex.rest.RestHttpServlet 子类后就需要对Service进行设置,设置需要三大注解:@RestController、@RestMapping、@RestParam。
+ 编写完 org.redkalex.rest.RestServlet 子类后就需要对Service进行设置,设置需要三大注解:@RestController、@RestMapping、@RestParam。
@RestController :
/**
@@ -231,7 +231,7 @@
private HelloService _service;
@AuthIgnore
- @WebMapping(url = "/hello/create")
+ @HttpMapping(url = "/hello/create")
public void create(HttpRequest req, HttpResponse resp) throws IOException {
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
UserInfo user = currentUser(req);
@@ -240,7 +240,7 @@
}
@AuthIgnore
- @WebMapping(url = "/hello/delete/")
+ @HttpMapping(url = "/hello/delete/")
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
int id = Integer.parseInt(req.getRequstURILastPath());
_service.deleteHello(id);
@@ -248,7 +248,7 @@
}
@AuthIgnore
- @WebMapping(url = "/hello/update")
+ @HttpMapping(url = "/hello/update")
public void update(HttpRequest req, HttpResponse resp) throws IOException {
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
_service.updateHello(bean);
@@ -256,7 +256,7 @@
}
@AuthIgnore
- @WebMapping(url = "/hello/query")
+ @HttpMapping(url = "/hello/query")
public void query(HttpRequest req, HttpResponse resp) throws IOException {
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
Flipper flipper = req.getFlipper();
@@ -265,7 +265,7 @@
}
@AuthIgnore
- @WebMapping(url = "/hello/find/")
+ @HttpMapping(url = "/hello/find/")
public void find(HttpRequest req, HttpResponse resp) throws IOException {
int id = Integer.parseInt(req.getRequstURILastPath());
HelloEntity bean = _service.findHello(id);
@@ -336,7 +336,7 @@
- 转换为RestHttpServlet如下:
+ 转换为RestServlet如下:
@WebServlet(value = {"/hello/*"}, repair = true)
public class _DynHelloRestServlet extends SimpleRestServlet {
@@ -345,7 +345,7 @@
private HelloService _service;
@AuthIgnore
- @WebMapping(url = "/hello/create")
+ @HttpMapping(url = "/hello/create")
public void create(HttpRequest req, HttpResponse resp) throws IOException {
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
UserInfo user = currentUser(req);
@@ -354,7 +354,7 @@
}
@AuthIgnore
- @WebMapping(url = "/hello/delete/")
+ @HttpMapping(url = "/hello/delete/")
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
int id = Integer.parseInt(req.getRequstURILastPath());
_service.deleteHello(id);
@@ -362,7 +362,7 @@
}
@AuthIgnore
- @WebMapping(url = "/hello/update")
+ @HttpMapping(url = "/hello/update")
public void update(HttpRequest req, HttpResponse resp) throws IOException {
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
_service.updateHello(bean);
@@ -370,7 +370,7 @@
}
@AuthIgnore
- @WebMapping(url = "/hello/partupdate")
+ @HttpMapping(url = "/hello/partupdate")
public void partupdate(HttpRequest req, HttpResponse resp) throws IOException {
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
String[] cols = req.getJsonParameter(String[].class, "cols");
@@ -379,7 +379,7 @@
}
@AuthIgnore
- @WebMapping(url = "/hello/query")
+ @HttpMapping(url = "/hello/query")
public void query(HttpRequest req, HttpResponse resp) throws IOException {
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
Flipper flipper = req.getFlipper();
@@ -388,7 +388,7 @@
}
@AuthIgnore
- @WebMapping(url = "/hello/list")
+ @HttpMapping(url = "/hello/list")
public void list(HttpRequest req, HttpResponse resp) throws IOException {
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
List<HelloEntity> result = _service.queryHello(bean);
@@ -396,7 +396,7 @@
}
@AuthIgnore
- @WebMapping(url = "/hello/find/")
+ @HttpMapping(url = "/hello/find/")
public void find(HttpRequest req, HttpResponse resp) throws IOException {
int id = Integer.parseInt(req.getRequstURILastPath());
HelloEntity bean = _service.findHello(id);
diff --git a/redkale.html b/redkale.html
index 48ac93a4a..a6b45441c 100644
--- a/redkale.html
+++ b/redkale.html
@@ -633,7 +633,7 @@
<!--
REST的核心配置项, 存在[rest]节点则Server启动时会加载REST服务, 当Server为SNCP协议时,则SncpServer会变成REST的HttpServer, 节点可以多个
- base: REST服务的BaseServlet,必须是 org.redkale.net.http.RestHttpServlet 的子类,该属性值默认值为 org.redkale.net.http.RestHttpServlet。
+ base: REST服务的BaseServlet,必须是 org.redkale.net.http.RestServlet 的子类,该属性值默认值为 org.redkale.net.http.RestServlet。
autoload:默认值"true" 默认值. 加载当前server所能使用的Servce对象;
mustsign:默认值"true" 是否只加载标记为RestService的Service类,默认只加载标记RestService且ignore=false的Service
includes:当autoload="true", 拉取类名与includes中的正则表达式匹配的类, 多个正则表达式用分号;隔开
diff --git a/service.html b/service.html
index fbd7ac20c..747f7dbe5 100644
--- a/service.html
+++ b/service.html
@@ -290,7 +290,7 @@
生成远程模式Service时发现参数带有@RpcCall注解的方法,在远程调用返回结果时会进行回调处理。
Service REST
- RestService提供类似Spring Boot的功能。开启REST功能的HTTP Server在实例化标记为@RestService的Service后自动生成对应的HttpServlet,免去开发人员编写HttpServlet的工作量。RestService生成的HttpServlet均是RestHttpServlet的子类。主要通过@RestService、@RestMapping、@RestParam这三个注解来实现,同时为了获取其他类型的参数也有@RestAddress、@RestCookie、@RestHeader、@RestSessionid、@RestBody 提供其扩展功能。
+ RestService提供类似Spring Boot的功能。开启REST功能的HTTP Server在实例化标记为@RestService的Service后自动生成对应的HttpServlet,免去开发人员编写HttpServlet的工作量。RestService生成的HttpServlet均是RestServlet的子类。主要通过@RestService、@RestMapping、@RestParam这三个注解来实现,同时为了获取其他类型的参数也有@RestAddress、@RestCookie、@RestHeader、@RestSessionid、@RestBody 提供其扩展功能。
@RestService :
@@ -386,18 +386,18 @@
String comment() default ""; //备注描述, 对应@HttpMapping.comment
}
- 开启REST功能的步骤很简单:在 application.xml 的 <server> 节点下增加<rest>指明RestHttpServlet的子类。
+ 开启REST功能的步骤很简单:在 application.xml 的 <server> 节点下增加<rest>指明RestServlet的子类。
<!--
REST的核心配置项, 存在[rest]节点则Server启动时会加载REST服务, 当Server为SNCP协议时,则SncpServer会变成REST的HttpServer, 节点可以多个
- base: REST服务的BaseServlet,必须是 org.redkale.net.http.RestHttpServlet 的子类,该属性值默认值为 org.redkale.net.http.RestHttpServlet。
+ base: REST服务的BaseServlet,必须是 org.redkale.net.http.RestServlet 的子类,该属性值默认值为 org.redkale.net.http.RestServlet。
autoload:默认值"true" 默认值. 加载当前server所能使用的Servce对象;
mustsign:默认值"true" 是否只加载标记为RestService的Service类,默认只加载标记RestService且ignore=false的Service
includes:当autoload="true", 拉取类名与includes中的正则表达式匹配的类, 多个正则表达式用分号;隔开
excludes:当autoload="true", 排除类名与excludes中的正则表达式匹配的类, 多个正则表达式用分号;隔开
-->
- <rest base="org.redkale.net.http.RestHttpServlet" mustsign="true" autoload="true" includes="" excludes="">
+ <rest base="org.redkale.net.http.RestServlet" mustsign="true" autoload="true" includes="" excludes="">
<!--
value: Service类名,列出的表示必须被加载的Service对象
ignore: 是否忽略,设置为true则不会加载该Service对象,默认值为false
@@ -407,9 +407,9 @@
Redkale中的REST并非严格遵循标准的REST规范,在尽量满足规范的同时也考虑到开发的灵活性和简易性。以下通过简单的实例来说明其特性。
- 通常配置都需要编写一个 org.redkale.net.http.RestHttpServlet 子类,主要用于获取当前用户信息和鉴权,且必须指定具体的User对象类。开发者的实现类可以参考 redkale-demo 中的BaseServlet类,以下是一个简单的范例:
+ 通常配置都需要编写一个 org.redkale.net.http.RestServlet 子类,主要用于获取当前用户信息和鉴权,且必须指定具体的User对象类。开发者的实现类可以参考 redkale-demo 中的BaseServlet类,以下是一个简单的范例:
- public class SimpleRestServlet extends RestHttpServlet<UserInfo> {
+ public class SimpleRestServlet extends RestServlet<UserInfo> {
protected static final RetResult RET_UNLOGIN = RetCodes.retResult(RetCodes.RET_USER_UNLOGIN);
@@ -560,7 +560,7 @@
@AuthIgnore
@HttpMapping(url = "/hello/create", comment = "创建Hello对象")
- @WebParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
+ @HttpParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
public void create(HttpRequest req, HttpResponse resp) throws IOException {
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
@@ -573,7 +573,7 @@
@AuthIgnore
@HttpMapping(url = "/hello/delete/", comment = "根据id删除Hello对象")
- @WebParam(name = "#", type = int.class, comment = "Hello对象id")
+ @HttpParam(name = "#", type = int.class, comment = "Hello对象id")
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
int id = Integer.parseInt(req.getRequstURILastPath());
@@ -583,7 +583,7 @@
@AuthIgnore
@HttpMapping(url = "/hello/update", comment = "修改Hello对象")
- @WebParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
+ @HttpParam(name = "bean", type = HelloEntity.class, comment = "Hello对象")
public void update(HttpRequest req, HttpResponse resp) throws IOException {
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
@@ -595,7 +595,7 @@
@AuthIgnore
@HttpMapping(url = "/hello/query", comment = "查询Hello对象列表")
- @WebParam(name = "bean", type = HelloBean.class, comment = "过滤条件")
+ @HttpParam(name = "bean", type = HelloBean.class, comment = "过滤条件")
public void query(HttpRequest req, HttpResponse resp) throws IOException {
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
@@ -610,7 +610,7 @@
@AuthIgnore
@HttpMapping(url = "/hello/find/", comment = "根据id查找单个Hello对象")
- @WebParam(name = "#", type = int.class, comment = "Hello对象id")
+ @HttpParam(name = "#", type = int.class, comment = "Hello对象id")
public void find(HttpRequest req, HttpResponse resp) throws IOException {
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
int id = Integer.parseInt(req.getRequstURILastPath());
@@ -620,7 +620,7 @@
@AuthIgnore
@HttpMapping(url = "/hello/asyncfind/", comment = "根据id查找单个Hello对象")
- @WebParam(name = "#", type = int.class, comment = "Hello对象id")
+ @HttpParam(name = "#", type = int.class, comment = "Hello对象id")
public void asyncfind(HttpRequest req, HttpResponse resp) throws IOException {
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
int id = Integer.parseInt(req.getRequstURILastPath());