File tree 3 files changed +56
-6
lines changed
demo/src/main/java/org/pyj/demo/handler
3 files changed +56
-6
lines changed Original file line number Diff line number Diff line change 4
4
import org .pyj .http .NettyHttpRequest ;
5
5
import org .pyj .http .annotation .NettyHttpHandler ;
6
6
import org .pyj .http .handler .IFunctionHandler ;
7
+ import org .pyj .http .handler .Result ;
7
8
8
9
/**
9
10
* @Description: http接口,参数化路径接口示例
10
11
* @Author: pengyongjian
11
12
* @Date: 2020-04-05 10:14
12
13
*/
13
14
@ NettyHttpHandler (path = "/temp/path/" ,equal = false )
14
- public class PathVariableHandler implements IFunctionHandler <Object > {
15
+ public class PathVariableHandler implements IFunctionHandler <String > {
15
16
16
17
@ Override
17
- public Object execute (NettyHttpRequest request ) {
18
+ public Result < String > execute (NettyHttpRequest request ) {
18
19
/**
19
20
* 通过请求uri获取到path参数
20
21
*/
21
22
String id = request .getStringPathValue (3 );
22
23
23
- return id ;
24
+ return new ResultJson < String >( 200 , id ) ;
24
25
}
25
26
}
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 3
3
import org .pyj .http .NettyHttpRequest ;
4
4
import org .pyj .http .annotation .NettyHttpHandler ;
5
5
import org .pyj .http .handler .IFunctionHandler ;
6
+ import org .pyj .http .handler .Result ;
6
7
7
8
/**
8
9
* @Description: http接口,向对应用户发送消息
9
10
* @Author: pengyongjian
10
11
* @Date: 2020-04-05 10:14
11
12
*/
12
13
@ NettyHttpHandler (path = "/temp/body" ,method = "POST" )
13
- public class TempHandler implements IFunctionHandler <Object > {
14
+ public class TempHandler implements IFunctionHandler <String > {
14
15
15
16
@ Override
16
- public Object execute (NettyHttpRequest request ) {
17
+ public Result < String > execute (NettyHttpRequest request ) {
17
18
String contentText = request .contentText ();
18
- return contentText ;
19
+ return new ResultJson < String >( 200 , contentText ) ;
19
20
}
20
21
}
You can’t perform that action at this time.
0 commit comments