账户密码设置
“IUserDao.java”增加代码
void updatePS(UserInfo userInfo);
“IUserService.java”增加代码
void updatePS(UserInfo userInfo);
“UserService.java”增加代码
@Override
public void updatePS(UserInfo userInfo) {
userDao.updatePS(userInfo);
}
“UserController.java”增加代码
@RequestMapping("upps.do")
@ResponseBody
public String upps(HttpSession session,String oldpassword,String password ){
UserInfo user= (UserInfo) session.getAttribute("user");
JSONObject jsonObject = new JSONObject();
if(!user.getPassword().equals(oldpassword)){
jsonObject.put("result",1);
}else {
user.setPassword(password);
userService.updatePS(user);
session.setAttribute("user",user);
jsonObject.put("result",2);
}
return jsonObject.toString();
}
“UserInfoMapper.xml”增加代码
<update id="updatePS" parameterType="com.yiju.bean.UserInfo">
update tb_user set password=#{password} where user_id=#{userId}
</update>
“psdsetting.jsp”代码如下
<html>
<head>
<title>账号密码设置中心</title>
<%--导入CSS文件--%>
<link type="text/css" href="../css/css.css" rel="stylesheet" />
<%--导入JS文件--%>
<script src="../js/jquery-2.1.1.min.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-00000000</strong></div>
<div class="clears"></div>
</td>
</tr>
</table>
</div><!--width1190/-->
</div><!--logo-phone/-->
<!--Logo栏和手机号栏 END-->
<hr width="1190px">
<br>
<div class="content">
<div class="width1080">
<%--左侧导航栏--%>
<div class="vip-left">
<div class="vipNav">
<h3 class="vipTitle">账户中心</h3>
<dl>
<dt class="vipIcon3">账户设置</dt>
<dd>
<a href="${pageContext.request.contextPath}/pages/personal.jsp" >我的资料</a>
<a href="${pageContext.request.contextPath}/user/verify.do">实名认证</a>
<a href="${pageContext.request.contextPath}/pages/psdsetting.jsp" class="vipNavCur">账户密码设置</a>
</dd>
<dt class="vipIcon1">我的易居</dt>
<dd>
<a href="/user/favorite.do">我的收藏房源</a>
</dd>
</dl>
</div><!--vipNav/-->
</div><!--vip-left/-->
<%--右侧详情栏--%>
<div class="vip-right">
<h3 class="vipright-title">我的认证</h3>
<br>
<table class="grinfo">
<tbody>
<tr>
<th ><span class="red">*</span>原 密 码:</th>
<td width="600px">
<input class="inp inw" type="password" name="oldpassword" id="oldpassword" value="" placeholder="请输入原密码!">
</td>
</tr>
<tr>
<td><br></td>
</tr>
<tr>
<th><span class="red">*</span>新 密 码:</th>
<td>
<input class="inp inw" type="password" name="password" id="password" value="" placeholder="请输入新密码!">
</td>
</tr>
<tr>
<td><br></td>
</tr>
<tr>
<th><span class="red">*</span>确认新密码:</th>
<td>
<input class="inp inw" type="password" name="password2" id="password2" value="" placeholder="请再次输入新密码!">
</td>
</tr>
<tr>
<td><br></td>
</tr>
<tr>
<th> </th>
<td colspan="2">
<label class="butt" id="butt">
<input type="submit" class="member_mod_buttom" onclick="" value="确认修改" />
</label>
</td>
</tr>
</tbody>
</table>
</div><!--vip-right/-->
<div class="clearfix"></div>
</div><!--width1190/-->
</div><!--content/-->
<!--End 个人信息填写栏-->
<div>
<br>
<br>
</div>
<!--这是页脚-->
<jsp:include page="../pages/basefoot.jsp"></jsp:include>
<script type="text/javascript">
$(function () {
$(".member_mod_buttom").on("click",function () {
var oldpassword=$("input[name=oldpassword]").val();
var password=$("input[name=password]").val();
var password2=$("input[name=password2]").val();
if(oldpassword==""){
alert("请输入旧密码");
return;
}
if (password==""){
alert("请输入新密码");
return;
}
if (password2==""){
alert("请输入确认密码");
return;
}
if(password!=password2){
alert("2次输入的密码不一样,请重新输入");
return;
}
$.ajax({
url:"${pageContext.request.contextPath}/user/upps.do",
type:"post",
dataType:"json",
data:{
oldpassword:oldpassword,
password:password
},
success:function (data) {
window.location.href="personal.jsp";
}
})
});
})
</script>
</body>
</html>
我的收藏房源–收藏房源
“IUserDao.java”增加代码
List<CollectView> getCollectViewByUser(int userId);
void addColletc(Collect collect);
Collect findByHouseType(@Param("userId") int userId,@Param("houseId") int houseId);
“IUserService.java”增加代码
List<CollectView> getCollectViewByUser(int userId);
void addColletc(Collect collect);
Collect findByHouseType(int userId,int houseId);
“UserService.java”增加代码
@Override
public List<CollectView> getCollectViewByUser(int userId) {
return userDao.getCollectViewByUser(userId);
}
```
@Override
public void addColletc(Collect collect) {
userDao.addColletc(collect);
}
@Override
public Collect findByHouseType(int userId, int houseId) {
return userDao.findByHouseType(userId,houseId);
}
“UserController.java”增加代码
@RequestMapping("favorite.do")
public ModelAndView favorite(HttpSession session){
UserInfo user= (UserInfo) session.getAttribute("user");
ModelAndView modelAndView=new ModelAndView();
List<CollectView> collects=userService.getCollectViewByUser(user.getUserId());
modelAndView.addObject("collects",collects);
modelAndView.setViewName("favorite");
return modelAndView;
}
@RequestMapping("addToColletc.do")
@ResponseBody
public String addToColletc(HttpSession session,int houseId){
UserInfo user= (UserInfo) session.getAttribute("user");
JSONObject jsonObject = new JSONObject();
Collect c=userService.findByHouseType(user.getUserId(),houseId);
if (c!=null){
jsonObject.put("result","0");
} else {
Collect collect=new Collect();
collect.setUserId(user.getUserId());
collect.setHouseId(houseId);
collect.setUpdateTime(new Date().getTime());
collect.setCreateTime(new Date().getTime());
userService.addColletc(collect);
jsonObject.put("result","1");
}
return jsonObject.toString();
}
“UserInfoMapper.xml”增加代码
<select id="getCollectViewByUser" parameterType="int" resultType="com.yiju.pojo.CollectView">
select * from tb_collect a,tb_house b where a.house_id=b.house_id and a.user_id=#{userId}
</select>
<insert id="addColletc" parameterType="com.yiju.bean.Collect">
insert into tb_collect(user_id,house_id,create_time,update_time)
value(#{userId},#{houseId},#{createTime},#{updateTime})
</insert>
<select id="findByHouseType" parameterType="int" resultType="com.yiju.bean.Collect">
select * from tb_collect where user_id=#{userId} and house_id=#{houseId}
</select>
“bean”中添加的“Collect.java”输入如下代码,并使用“Getter and Setter”和“toString”方法
private int collId; //收藏记录的唯一标识ID
private int userId; //用户ID
private int houseId; //用户收藏的房源ID
private int isDelete; //是否删除 0-未删除 1-已删除
private long createTime; //创建时间
private long updateTime; //更新时间
“favorite.jsp”代码如下
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: 36353
Date: 2019-07-05
Time: 15:14
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 rel="stylesheet" type="text/css" href="../css/styleCollect.css" />
</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-00000000</strong></div>
<div class="clears"></div>
</td>
</tr>
</table>
</div><!--width1190/-->
</div><!--logo-phone/-->
<!--Logo栏和手机号栏 END-->
<hr width="1190px">
<br>
<div class="content">
<div class="width1080">
<%--左侧导航栏--%>
<div class="vip-left">
<div class="vipNav">
<h3 class="vipTitle">账户中心</h3>
<dl>
<dt class="vipIcon3">账户设置</dt>
<dd>
<a href="${pageContext.request.contextPath}/pages/personal.jsp" >我的资料</a>
<a href="${pageContext.request.contextPath}/user/verify.do">实名认证</a>
<a href="${pageContext.request.contextPath}/pages/psdsetting.jsp">账户密码设置</a>
</dd>
<dt class="vipIcon1">我的易居</dt>
<dd>
<a href="/user/favorite.do" class="vipNavCur">我的收藏房源</a>
</dd>
</dl>
</div><!--vipNav/-->
</div><!--vip-left/-->
<%--右侧详情栏--%>
<div class="vip-right">
<h3 class="vipright-title">我的收藏</h3>
<div class="AGrid-row tool-package">
<c:forEach var="collcetView" items="${collects}">
<div class="col-sm-6 ">
<div class="tile center-layer">
<div class="layer-figure">
<a href="/house/todetails.do?house_id=${collcetView.houseId}">
<img src="http://image.cxhit.com/${collcetView.houseHeadimg}">
</a>
</div>
<h2 class="dev-list"> <a href="/house/todetails.do?houseId=${collcetView.houseId}">${collcetView.houseTitle}</a></h2>
<div class="layer-text">
<p class="dev-text">${collcetView.houseAddress}</p>
<div class="layer-btn">
<a href="/user/removeColl.do?coll_id=${collcetView.collId}">
<p>移出收藏</p>
</a>
</div>
</div>
</div>
</div>
</c:forEach>
</div>
</div><!--vip-right/-->
<div class="clearfix"></div>
</div><!--width1190/-->
</div><!--content/-->
<!--End 个人信息填写栏-->
<!--这是页脚-->
<jsp:include page="../pages/basefoot.jsp"></jsp:include>
</body>
</html>
详情页分页
“houses.jsp”分页相关代码如下
<%--分页按钮--%>
<div class="pull-right">
<ul class="pagination">
<li>
<a href="${pageContext.request.contextPath}/house/findHouse.do?houseType=${pageInfo.list.get(0).houseType}¤tPage=${pageInfo.firstPage}"
aria-label="Previous">首页</a></li>
<li>
<a href="${pageContext.request.contextPath}/house/findHouse.do?houseType=${pageInfo.list.get(0).houseType}¤tPage=${pageInfo.pageNum - 1}">上一页</a>
</li>
<c:forEach begin="1" end="${pageInfo.pages}" var="pageNum">
<li>
<a href="${pageContext.request.contextPath}/house/findHouse.do?houseType=${pageInfo.list.get(0).houseType}¤tPage=${pageNum}">${pageNum}</a>
</li>
</c:forEach>
<li>
<a href="${pageContext.request.contextPath}/house/findHouse.do?houseType=${pageInfo.list.get(0).houseType}¤tPage=${pageInfo.pageNum + 1}">下一页</a>
</li>
<li>
<a href="${pageContext.request.contextPath}/house/findHouse.do?houseType=${pageInfo.list.get(0).houseType}¤tPage=${pageInfo.lastPage}"
aria-label="Next">尾页</a></li>
</ul>
</div><!--底部分页栏-->