我正在使用 REST API 开发 Web 服务。我想获取用户在 URL 中输入的内容。例如,如果用户请求“http://localhost:8080/employee?ename=john ”,那么我想获取“john”,以便我可以使用该值进行进一步检查。我怎样才能得到这个变量?
最佳答案
@Controller
@RequestMapping("/employee")
public class Employee {
@RequestMapping(value="", method=RequestMethod.GET)
public String disp(HttpServletRequest request, @RequestParam(value="ename", required=false) String ename) {
// used
System.out.println(ename); // voted
// or
request.getParameter("ename");
}
}
关于java - 从用户获取 http 请求并使用 REST API 将该变量值存储到任何数据结构中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47446967/