使用Map<>
dao 类
User finselect (Map<String,ob>> map);
service 类
User finselect (String name,String pwd);
serviceImpl 类
pubilc User finselect (String name,String pwd){
Map<String,Ob> map =new HashMap<>();
map.put("name",name);
map.put("pwd",pwd);
retrun ud.finb(map);
}
controller类
@ResponseBody
@RequestMapping(value = "/login", method = RequestMethod.POST)
private Map<String,Object> login(@RequestBody User user) {
Map<String,Object> map = new HashMap<>();
User my = userService.findUser(user.getName(),user.getPassword());
if(my != null)
{
map.put("flag",1);
}
else
{
map.put("flag",0);
}
return map;
}
sql语句
<select id="login" parameterType="Map" resulttype="User">
select * from tb_user where name=#{name} and password=#{password}
</select>
jsp界面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>
<html ng-app="">
<head>
<title>登录</title>
<script src="../resources/angularJs/angular-1.0.1.min.js"></script>
</head>
<body ng-controller="myController">
用户名:<input type="text" name="name" id="name" ng-model="user.name"><br>
密码:<input type="password" name="password" id="password" ng-model="user.password"><br>
<button ng-click="getUser()">登录</button>
</body>
<script>
function myController($scope, $http){
//复初值
$scope.user = {
name:"xyj",
password:"111"
};
$scope.getUser = function(){
$http({
method: "POST",
url: "<%=basePath%>/book/login.action",
data: $scope.user,
dataType:"json"
}).success(function (data){
if(data.flag == 1)
{
window.location.href = "<%=basePath%>/book/findBookList.action?pageNum=1";
}
else
{
alert("登录失败");
}
}).error(function(){
alert("登录失败");
})
};
}
</script>
</html>
1.引用过来angular-1.0.1.min.js
2.在登录页面添加引用,放在head区域中,页面记得不要加form表单
3.需要标注的节点
<html ng-app="">
<body ng-controller="myController">
用户名:<input type="text" name="name" id="name" ng-model="user.name"><br>
<button ng-click="getUser()">登录</button>
4.controller方法,要标注@ResponseBody,入参要对象前加@RequestBody,返回值类型用Map<String,Object>