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";
}
相關文章
相關標籤/搜索