SpringMVC + Spring + MyBatis 學習筆記:在類和方法上都使用RequestMapping如何訪問

來源:互聯網
上載者:User

標籤:

系統:WIN8.1

資料庫:Oracle 11GR2

開發工具:MyEclipse 8.6

架構:Spring3.2.9、SpringMVC3.2.9、MyBatis3.2.8

先看代碼:

@RequestMapping(value="manager")@Controller("managerController")public class ManagerController {        /**     * 後台使用者登入     * @param request     * @param emp     * @return     */    @RequestMapping(params="login" , method={RequestMethod.POST})    public String login(HttpServletRequest request , Employe emp){                request.getSession().setAttribute(SystemConstant.MANAGER, emp);        return "redirect:index.jsp";    }            /**     * 後台使用者退出     * @param request     * @return     */    @RequestMapping(params="logout" , method={RequestMethod.POST,RequestMethod.GET})    public String logout(HttpServletRequest request){                request.getSession().removeAttribute(SystemConstant.MANAGER);        return "login";    }}

類上面有配置RequestMapping,訪問路徑為 manager ,方法上面這次配置的是params,值為login和logout。
頁面發起訪問路徑由 類的訪問名稱 + 方法的訪問名稱/參數名稱

頁面請看form的action ,如果是get方法或者超連結也是一樣,當然要記得添加參數

<form class="form-horizontal" action="manager?login" method="post">
                    <div class="form-group">
                      <label class="control-label col-lg-3" for="inputEmail">帳號</label>
                      <div class="col-lg-9">
                        <input type="text" class="form-control" id="inputEmail" placeholder="帳號" name="empName">
                      </div>
                    </div>
                    <div class="form-group">
                      <label class="control-label col-lg-3" for="inputPassword">密碼</label>
                      <div class="col-lg-9">
                        <input type="password" class="form-control" id="inputPassword" placeholder="密碼" name="empPassword">
                      </div>
                    </div>
                        <div class="col-lg-9 col-lg-offset-2">
                            <button type="submit" class="btn btn-danger">登陸</button>
                            <button type="reset" class="btn btn-default">重設</button>
                        </div>
                    <br />
                  </form>

 

SpringMVC + Spring + MyBatis 學習筆記:在類和方法上都使用RequestMapping如何訪問

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.