Skip to content

Commit d795e97

Browse files
author
pengyongjian
committed
first commit
1 parent 958f351 commit d795e97

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

demo/src/main/java/org/pyj/demo/handler/PathVariableHandler.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,23 @@
44
import org.pyj.http.NettyHttpRequest;
55
import org.pyj.http.annotation.NettyHttpHandler;
66
import org.pyj.http.handler.IFunctionHandler;
7+
import org.pyj.http.handler.Result;
78

89
/**
910
* @Description: http接口,参数化路径接口示例
1011
* @Author: pengyongjian
1112
* @Date: 2020-04-05 10:14
1213
*/
1314
@NettyHttpHandler(path = "/temp/path/",equal = false)
14-
public class PathVariableHandler implements IFunctionHandler<Object> {
15+
public class PathVariableHandler implements IFunctionHandler<String> {
1516

1617
@Override
17-
public Object execute(NettyHttpRequest request) {
18+
public Result<String> execute(NettyHttpRequest request) {
1819
/**
1920
* 通过请求uri获取到path参数
2021
*/
2122
String id = request.getStringPathValue(3);
2223

23-
return id;
24+
return new ResultJson<String>(200, id);
2425
}
2526
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.pyj.demo.handler;
2+
3+
import org.pyj.http.handler.Result;
4+
5+
import java.io.Serializable;
6+
7+
/**
8+
* @author pengyongjian
9+
* @Description:
10+
* @date 2020/12/21 下午3:51
11+
*/
12+
public class ResultJson<T> implements Result<T>, Serializable {
13+
14+
private static final long serialVersionUID = 1;
15+
16+
private int code;
17+
18+
private T t;
19+
20+
public ResultJson(int code, T t) {
21+
this.code = code;
22+
this.t = t;
23+
}
24+
25+
public int getCode() {
26+
return code;
27+
}
28+
29+
public void setCode(int code) {
30+
this.code = code;
31+
}
32+
33+
public T getT() {
34+
return t;
35+
}
36+
37+
public void setT(T t) {
38+
this.t = t;
39+
}
40+
41+
@Override
42+
public String toString() {
43+
return "ResultJson{" +
44+
"code=" + code +
45+
", t=" + t +
46+
'}';
47+
}
48+
}

demo/src/main/java/org/pyj/demo/handler/TempHandler.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
import org.pyj.http.NettyHttpRequest;
44
import org.pyj.http.annotation.NettyHttpHandler;
55
import org.pyj.http.handler.IFunctionHandler;
6+
import org.pyj.http.handler.Result;
67

78
/**
89
* @Description: http接口,向对应用户发送消息
910
* @Author: pengyongjian
1011
* @Date: 2020-04-05 10:14
1112
*/
1213
@NettyHttpHandler(path = "/temp/body",method = "POST")
13-
public class TempHandler implements IFunctionHandler<Object> {
14+
public class TempHandler implements IFunctionHandler<String> {
1415

1516
@Override
16-
public Object execute(NettyHttpRequest request) {
17+
public Result<String> execute(NettyHttpRequest request) {
1718
String contentText = request.contentText();
18-
return contentText;
19+
return new ResultJson<String>(200, contentText);
1920
}
2021
}

0 commit comments

Comments
 (0)