Skip to content

Commit 3c2ee9c

Browse files
committed
【Doe_V1.2.0】 增加泛型接口、参数测试
1 parent 049c8f7 commit 3c2ee9c

File tree

6 files changed

+133
-0
lines changed

6 files changed

+133
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
3+
*
4+
* This software is the confidential and proprietary information of
5+
* Founder. You shall not disclose such Confidential Information
6+
* and shall use it only in accordance with the terms of the agreements
7+
* you entered into with Founder.
8+
*
9+
*/
10+
package com.mmc.dubbo.api.user;
11+
12+
import java.io.Serializable;
13+
14+
/**
15+
* @author Joey
16+
* @date 2019/5/10 16:10
17+
*/
18+
public class GenericReq<T> implements Serializable {
19+
20+
21+
private static final long serialVersionUID = 3998577120137245599L;
22+
private String name;
23+
private T data;
24+
25+
public String getName() {
26+
return name;
27+
}
28+
29+
public void setName(String name) {
30+
this.name = name;
31+
}
32+
33+
public T getData() {
34+
return data;
35+
}
36+
37+
public void setData(T data) {
38+
this.data = data;
39+
}
40+
}
41+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2010-2020 Founder Ltd. All Rights Reserved.
3+
*
4+
* This software is the confidential and proprietary information of
5+
* Founder. You shall not disclose such Confidential Information
6+
* and shall use it only in accordance with the terms of the agreements
7+
* you entered into with Founder.
8+
*
9+
*/
10+
package com.mmc.dubbo.api.user;
11+
12+
import java.io.Serializable;
13+
14+
/**
15+
* @author Joey
16+
* @date 2019/5/10 16:11
17+
*/
18+
public class GenericResp<T> implements Serializable {
19+
20+
private static final long serialVersionUID = 6753766666093779059L;
21+
private T data;
22+
private String name;
23+
24+
public T getData() {
25+
return data;
26+
}
27+
28+
public void setData(T data) {
29+
this.data = data;
30+
}
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public void setName(String name) {
37+
this.name = name;
38+
}
39+
}

mmc-dubbo-api/src/main/java/com/mmc/dubbo/api/user/UserFact.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
public class UserFact implements Serializable {
1919

20+
private static final long serialVersionUID = 2798561567572955369L;
2021
private long id;
2122
private String name;
2223
private int sex;

mmc-dubbo-api/src/main/java/com/mmc/dubbo/api/user/UserService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@ public interface UserService {
3232
*/
3333
UserFact insert(UserFact u, String name, int sex);
3434

35+
/**
36+
* 泛型测试.
37+
* @param user
38+
* @return
39+
*/
40+
GenericResp<UserFact> echo(GenericReq<UserFact> user);
41+
3542
}
43+

mmc-dubbo-provider/src/main/java/com/mmc/dubbo/provider/user/UserFeedbackServiceImpl.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99
*/
1010
package com.mmc.dubbo.provider.user;
1111

12+
import com.alibaba.fastjson.JSON;
13+
import com.mmc.dubbo.api.user.GenericReq;
14+
import com.mmc.dubbo.api.user.GenericResp;
1215
import com.mmc.dubbo.api.user.UserFact;
1316
import com.mmc.dubbo.api.user.UserService;
17+
import org.springframework.beans.BeanUtils;
1418

1519
/**
1620
* @author Joey
@@ -55,4 +59,20 @@ public UserFact insert(UserFact u, String name, int sex) {
5559

5660
return userFact;
5761
}
62+
63+
/**
64+
* 泛型测试.
65+
*
66+
* @param user
67+
* @return
68+
*/
69+
@Override
70+
public GenericResp<UserFact> echo(GenericReq<UserFact> user) {
71+
System.out.println(JSON.toJSONString(user));
72+
73+
GenericResp<UserFact> resp = new GenericResp<>();
74+
BeanUtils.copyProperties(user, resp);
75+
76+
return resp;
77+
}
5878
}

mmc-dubbo-provider/src/main/java/com/mmc/dubbo/provider/user/UserMemberServiceImpl.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
*/
1010
package com.mmc.dubbo.provider.user;
1111

12+
import com.alibaba.fastjson.JSON;
13+
import com.mmc.dubbo.api.user.GenericReq;
14+
import com.mmc.dubbo.api.user.GenericResp;
1215
import com.mmc.dubbo.api.user.UserFact;
1316
import com.mmc.dubbo.api.user.UserService;
17+
import org.slf4j.MDC;
18+
import org.springframework.beans.BeanUtils;
1419

1520
/**
1621
* @author Joey
@@ -46,4 +51,23 @@ public UserFact insert(UserFact u, String name, int sex) {
4651
return userFact;
4752

4853
}
54+
55+
/**
56+
* 泛型测试.
57+
*
58+
* @param user
59+
* @return
60+
*/
61+
@Override
62+
public GenericResp<UserFact> echo(GenericReq<UserFact> user) {
63+
64+
System.out.println(JSON.toJSONString(user));
65+
66+
System.out.println("msp: " + MDC.getCopyOfContextMap());
67+
68+
GenericResp<UserFact> resp = new GenericResp<>();
69+
BeanUtils.copyProperties(user, resp);
70+
71+
return resp;
72+
}
4973
}

0 commit comments

Comments
 (0)