mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
新增restful模式
This commit is contained in:
@@ -6,6 +6,8 @@ import com.sop.example.rest.examplerest.rest.GoodsController;
|
||||
import com.sop.example.rest.examplerest.rest.vo.GoodsVO;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -16,13 +18,26 @@ import java.util.Map;
|
||||
public class GoodsControllerImpl implements GoodsController {
|
||||
@Override
|
||||
public GoodsVO getById(Integer id) {
|
||||
WebContext webContext = WebContext.current();
|
||||
GoodsVO goodsVO = new GoodsVO();
|
||||
goodsVO.setId(id);
|
||||
goodsVO.setName("冰箱");
|
||||
|
||||
Map<String, String> headers = WebContext.current().getHeaders();
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
list.add("realIp:" + webContext.getRealIp());
|
||||
|
||||
Map<String, String> headers = webContext.getHeaders();
|
||||
String token = headers.get("token");
|
||||
System.out.println(token);
|
||||
list.add("token:" + token);
|
||||
|
||||
String remoteAddr = webContext.getRemoteAddr();
|
||||
list.add("remoteAddr:" + remoteAddr);
|
||||
|
||||
String idValue = webContext.getParameter("id");
|
||||
list.add("id:" + idValue);
|
||||
|
||||
goodsVO.setRemark(list.toString());
|
||||
return goodsVO;
|
||||
}
|
||||
}
|
||||
|
@@ -12,4 +12,6 @@ public class GoodsVO {
|
||||
|
||||
private String name;
|
||||
|
||||
private String remark;
|
||||
|
||||
}
|
||||
|
@@ -119,6 +119,7 @@ public class ParamExecutorImpl implements ParamExecutor<HttpServletRequest, Http
|
||||
defaultWebContext.setLocale(request.getLocale());
|
||||
defaultWebContext.setHeaders(RequestUtil.getHeaders(request));
|
||||
defaultWebContext.setParamtreMap(new LinkedHashMap<>(request.getParameterMap()));
|
||||
defaultWebContext.setRealIp(RequestUtil.getIP(request));
|
||||
return defaultWebContext;
|
||||
}
|
||||
|
||||
|
@@ -33,6 +33,7 @@ public class DefaultWebContext extends WebContext implements Serializable {
|
||||
private Locale locale;
|
||||
private Map<String, String> headers;
|
||||
private Map<String, String[]> paramtreMap;
|
||||
private String realIp;
|
||||
|
||||
@Override
|
||||
public String getParameter(String name) {
|
||||
|
@@ -58,6 +58,11 @@ public abstract class WebContext {
|
||||
*/
|
||||
public abstract Map<String, String> getHeaders();
|
||||
|
||||
/**
|
||||
* 获取真实ip地址
|
||||
*/
|
||||
public abstract String getRealIp();
|
||||
|
||||
protected void setContext(WebContext openContext) {
|
||||
THREAD_LOCAL.set(openContext);
|
||||
}
|
||||
|
Reference in New Issue
Block a user