学习备忘,节约时间。
1、代码
/** * @author Spqin * @Date 2020/11/5 11:28 */ @Slf4j @RestController @RequestMapping("/test") public class TestController { @RequestMapping("/test") public String page(HttpServletRequest request,HttpServletResponse response){ //request.getContextPath() 返回 /项目名 //request.getRequestURI()() 返回 /项目名+请求的控制器地址(本例子对应的是/test/test) //String httpUrl = request.getScheme()+"://" + request.getServerName() + ":" +request.getServerPort()+request.getContextPath()+request.getRequestURI()+"?"+request.getQueryString(); String httpUrl = request.getScheme()+"://" + request.getServerName() + ":" +request.getServerPort()+request.getRequestURI()+"?"+request.getQueryString(); System.out.println(httpUrl); return httpUrl; } }
2、使用域名测试输出结果
3、使用ip地址测试输出结果