系统: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 "redirect:login.html";
}
}
类上面有配置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>