作者:liu-zebing_284 | 来源:互联网 | 2023-02-06 04:47
1.第一步登录并验证(index.jsp)
登陆开始
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
cOntent="Charisma, a fully featured, responsive, HTML5, Bootstrap admin template.">
rel="stylesheet">
media=‘print‘>
(登录验证index.js)
$("#loginBtn").click(function(){
var user=new Object();
user.loginCode=$.trim($("#loginCode").val());
user.password=$.trim($("#password").val());
user.isStart=1;
if(user.loginCode==""||user.loginCode==null){
$("#loginCode").focus();
$("#formtip").css("color","red");
$("#formtip").html("对不起,登录账号不能为空。");
}else if(user.password==""||user.password==null){
$("#password").focus();
$("#formtip").css("color","red");
$("#formtip").html("对不起登录密码不能为空。");
}else{
$("#formtip").html("");
$.ajax({
type:‘post‘,
url:‘/login.html‘,
data:{user:JSON.stringify(user)},
dataType:‘html‘,
timeout:1000,
error:function(){
$("#formtip").css("color","red");
$("#formtip").html("登录失败!请从试。");
},
success:function(result){
if(result!=""&&result=="success"){
window.location.href=‘/main.html‘;
}else if("failed"==result){
$("#formtip").css("color","red");
$("#formtip").html("登录失败,请从新登录");
$("#loginCode").val(‘‘);
$("#loginCode").focus();
$("#password").val(‘‘);
}else if(result=="nologincode"){
$("#formtip").css("color","red");
$("#loginCode").val(‘‘);
$("#loginCode").focus();
$("#formtip").html("登录账号不存在,请重新登录");
}else if(result=="pwderror"){
$("#formtip").css("color","red");
$("#password").val(‘‘).focus();
$("#formtip").html("登录密码不正确,请重新输入");
}else if(result=="nodata"){
$("#formtip").css("color","red");
$("#formtip").html("对不起没有任何数据需要处理!请输入");
}
}
});
}
});
第二步:UserMapper接口
1
public interface UserMapper {
/**
* 获取登录用户
*getLoginUser
* @param user
* @return
* @throws Exception
*/
public User getLoginUser(User user) throws Exception;
/**
* loginCodeIsExit
* 判断登录用户是否存在
* @param user
* @return
* @throws Exception
*/
public int loginCodeIsExit(User user) throws Exception;
}
2userMappper.xml
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
SLSystem会员商城