SpringMVC 控制器默认支持GET和POST两种办法
发布时间:2021-11-13 12:13:03 所属栏目:教程 来源:互联网
导读:在SpringMVC的controller中,@RequestMapping只写路径,不包含RequetMethod.GET和RequetMethod.POST,HttpServletRequest的getParameter(*)方法同时支持这两种方式。 1 @RequestMapping(savedata) 2 public @ResponseBody void savedata(HttpServletRequest
|
在SpringMVC的controller中,@RequestMapping只写路径,不包含RequetMethod.GET和RequetMethod.POST,HttpServletRequest的getParameter(“*”)方法同时支持这两种方式。 1 @RequestMapping("savedata") 2 public @ResponseBody void savedata(HttpServletRequest req, HttpServletResponse resp) throws Exception { 3 4 String taskClass = req.getParameter("taskclass"); ServletRequest接口中对该方法的说明如下,可以从请求字符串(URL)和POST实体(通过getInputStream和getReader方法)中读取参数: /** * Returns the value of a request parameter as a <code>String</code>, * or <code>null</code> if the parameter does not exist. Request parameters * are extra information sent with the request. For HTTP servlets, * parameters are contained in the query string or posted form data. * * <p>You should only use this method when you are sure the * parameter has only one value. If the parameter might have * more than one value, use {@link #getParameterValues}. * * <p>If you use this method with a multivalued * parameter, the value returned is equal to the first value * in the array returned by <code>getParameterValues</code>. * * <p>If the parameter data was sent in the request body, such as occurs * with an HTTP POST request, then reading the body directly via {@link * #getInputStream} or {@link #getReader} can interfere * with the execution of this method. * * @param name a <code>String</code> specifying the name of the parameter * * @return a <code>String</code> representing the single value of * the parameter * * @see #getParameterValues */ public String getParameter(String name); ![]() (编辑:开发网_开封站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |



浙公网安备 33038102330459号