java获取前台参数的几种方式

一、第一种 

@RequestMapping("/updateHumanInfo")
public void updateHumanInfo(HttpServletRequest request) {
    StringBuffer sb = new StringBuffer("");
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(request.getInputStream(), "utf-8"));
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    System.out.println(sb.toString());
    JSONObject json = JSONObject.parseObject(sb.toString());
}

二、第二种

@RequestMapping("/updateHumanInfo.htm")
public void updateHumanInfo(String name) {
    System.out.pringln(name);
}

三、第三种

@RequestMapping("/updateHumanInfo.htm")
public void updateHumanInfo(HttpServletRequest request) {
	StandardMultipartHttpServletRequest req = (StandardMultipartHttpServletRequest) request;
    Iterator iterator = req.getFileNames();
    
	while (iterator.hasNext()) {
		try {
			MultipartFile file = req.getFile(iterator.next());
            String fileName = file.getOriginalFilename();
            byte[] b = file.getBytes();
		}catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}

四、第四种

@RequestMapping("/updateHumanInfo.htm")
public void updateHumanInfo(HttpServletRequest request) {
	Enumeration params = request.getParameterNames();
    while (params.hasMoreElements()) {
		String name = params.nextElement().toString();
		String val = params.getParameter(name);
    }
}

 

 

你可能感兴趣的:(java)