在“易居住房6”的基础上进行增加或修改代码
注册
“IUserDao.java”增加代码
void singup(@Param("phone") String phone,@Param("password") String password);
“IUserService.java”增加代码
void add(String phone, String password);
“UserService.java”增加代码
@Override
public void add(String phone, String password) {
userDao.singup(phone,password);
}
“UserController.java”增加代码
“登录”代码的修改
在@Param(value = "password") String password,
后加HttpSession session
;在jsonObject.put("result","2");
前加session.setAttribute("user",user);
;增加“singup.do”代码块
@RequestMapping("singup.do")
@ResponseBody
public String singup(@Param(value = "phone") String phone,
@Param(value = "password") String password){
//1.查看该手机号是否注册
//2.已注册提示,跳转到登录页面
//3.没有注册,需注册
JSONObject jsonObject=new JSONObject();
UserInfo user=userService.findUserByPhon(phone);
if (user==null){
userService.add(phone,password);
jsonObject.put("result","0");
} else if (!password.equals(user.getPassword())){
jsonObject.put("result","1");
} else {
jsonObject.put("result","2");
}
return jsonObject.toString();
}
“UserInfoMapper.xml”增加代码
<select id="singup" parameterType="String">
insert into tb_user(phone,password) values (#{phone},#{password})
</select>
“pages”中添加“signup.jsp”–注册页面,“personal.jsp”–个人中心页面
“signup.jsp”代码如下
<%--
Created by IntelliJ IDEA.
User: 36353
Date: 2019-07-03
Time: 16:38
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>欢迎注册 — 易居住房交易平台</title>
<%--导入CSS文件--%>
<link type="text/css" href="../css/css.css" rel="stylesheet" />
<link type="text/css" href="../css/buttonStyle.css" rel="stylesheet" />
<%--导入JS文件--%>
<script src="../js/jquery-2.1.1.min.js"></script>
<%--<script src="js/signup.js"></script>--%>
</head>
<body>
<%--加入头部--%>
<jsp:include page="../pages/basehead.jsp"></jsp:include>
<!--Logo栏和手机号栏-->
<div class="logo-phone">
<div class="width1190">
<table align="center" width="100%">
<tr>
<td>
<h1 class="logo"><a href="../index.jsp"><img src="../images/logo.png" width="163" height="59" /></a></h1>
</td>
<td align="center">
<div class="phones"><strong>000-0000000</strong></div>
<div class="clears"></div>
</td>
</tr>
</table>
</div><!--width1190/-->
</div><!--logo-phone/-->
<!--Logo栏和手机号栏-->
<!--Logo栏和手机号栏-->
<hr width="1280px">
<!--注册-->
<div class="content&