springMVC接收表单的三种方式

第一种 经过@RequestParam方式app

前台表单:编码

<form id="spcialEventForm" action="${pageContext.request.contextPath}/appre/save">
    <div class="form-group">
        <label>活动编码:</label>
        <input type="text" class="form-control" name="hdbm">
    </div>

    <div class="form-group">
        <label >活动名称:</label>
        <input type="text" class="form-control" name="hdmc">
    </div>
  <input type="submit" value="提交"/>
</form>

controller后台:orm

@RequestMapping(value = "/save")
public String saveSpecialEvent(@RequestParam("hdbm") String hdbm,
                               @RequestParam("hdmc") String hdmc)
{
    System.out.println("==="+hdbm);
    System.out.println("==="+hdmc);


    return "appraise/specialEvent/specialEvent";
}

第二种 bean写好后   直接把表单的参数写在Controller相应的方法的形参中     ci

前台不变get

后台以下input

@RequestMapping(value = "/save")
public String saveSpecialEvent(String hdbm, String hdmc)
{
    System.out.println("==="+hdbm);
    System.out.println("==="+hdmc);


    return "appraise/specialEvent/specialEvent";
}

第三种 HttpServletRequest接收it

前台相同io

后台以下event

@RequestMapping(value = "/save")
public String saveSpecialEvent(HttpServletRequest request)
{
    System.out.println("==="+request.getParameter("hdbm"));
    System.out.println("==="+request.getParameter("hdmc"));


    return "appraise/specialEvent/specialEvent";
}

第四种 经过Bean接收  form

前台表单各项name与bean对照 后台controller直接传入Bean

@RequestMapping(value = "/save")
public String saveSpecialEvent(AppraiseSpecialevent specialevent)
{
    System.out.println("--"+specialevent.getHdbm());
    System.out.println("--"+specialevent.getHdjb());
    System.out.println("--"+specialevent.getHdzzdw());
    System.out.println("--"+specialevent.getHdfzr());
    System.out.println("--"+specialevent.getBmmc());
    System.out.println("--"+specialevent.getHdcyry());
    System.out.println("--"+specialevent.getBmmc());
    System.out.println("--"+specialevent.getHdkzrq());
    System.out.println("--"+specialevent.getCykhrq());
    System.out.println("--"+specialevent.getWj());


    return "appraise/specialEvent/specialEvent";
}
相关文章
相关标签/搜索