房产信息管理系统--顾客功能实现
房产信息管理系统--顾客功能实现
总实现:test房产信息管理系统 - yuanse - 博客园 (cnblogs.com)
1.user.jsp(顾客总功能选择页面)
<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/19 Time: 19:28 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>user.jsp</title> </head> <%--顾客功能页--%> <body> <% String uname=(String) request.getSession().getAttribute("uname"); %> <table align="center" width="400"> <a href="usinfo.jsp?usname=<%=uname%>">查看个人信息</a><br> <a href="uspwd.jsp?usname=<%=uname%>">修改个人密码</a><br> <a href="usliulan.jsp?usname=<%=uname%>">浏览房产信息</a><br> <a href="usliulan.jsp?usname=<%=uname%>">购买房产</a><br> </table> </body> </html>
2.usinfo.jsp(顾客查看个人信息页面)
<%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="com.xxxx.mapper.UserMapper" %> <%@ page import="com.xxxx.entity.User" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/28 Time: 21:53 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>usinfo.jsp</title> </head> <%--顾客功能:查看个人信息页面--%> <body> <% String usname=request.getParameter("usname"); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); UserMapper userMapper=sqlSession.getMapper(UserMapper.class); User user=userMapper.selectByusname(usname); %> <table align="center" width="800"> <tr> <td>顾客ID</td><td>姓名</td><td>性别</td><td>身份证号</td><td>手机</td><td>家庭住址</td> </tr> <tr><td><%=user.getUsid()%></td> <td><%=user.getUsname()%></td><td><%=user.getUssex()%></td><td><%=user.getUsidnum()%></td><td><%=user.getUsphone()%></td><td><%=user.getUsaddress()%></td> </tr> </table> </body> </html>
3.uspwd.jsp(顾客修改个人密码页面)
<%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="com.xxxx.mapper.LoginMapper" %> <%@ page import="com.xxxx.entity.Login" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/28 Time: 22:00 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>uspwd.jsp</title> </head> <%--顾客修改个人密码页面,要判断:输入的密码是否和旧密码相同--%> <body> <% String usname=request.getParameter("usname"); request.getSession().setAttribute("usname",usname); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); LoginMapper loginMapper=sqlSession.getMapper(LoginMapper.class); Login login=loginMapper.selectByusname(usname); %> <form action="uspwdServlet" method="post" id="uspwdForm"> 输入旧密码:<input type="password" name="uspwd1" id="uspwd1"><br> 输入新密码:<input type="password" name="uspwd2" id="uspwd2"><br> 确认新密码:<input type="password" name="uspwd3" id="uspwd3"><br> <button type="button" id="uspwdBtn">修改</button> </form> <script type="text/javascript" src="js/jquery-3.6.1.js"></script> <script type="text/javascript"> $("#uspwdBtn").click(function (){ var uspwd1=$("#uspwd1").val(); var uspwd2=$("#uspwd2").val(); var uspwd3=$("#uspwd3").val(); if(uspwd1 != <%=login.getUpwd()%>)alert("旧密码有误"); else { if(uspwd2 != uspwd3) alert("两次输入的新密码不相同"); else $("#uspwdForm").submit(); } }) </script> </body> </html>
4.uspwdServlet(顾客修改个人密码Servlet)
package com.xxxx.servlet; import com.mysql.cj.log.Log; import com.xxxx.entity.Login; import com.xxxx.mapper.LoginMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet("/uspwdServlet") public class uspwdServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); String usname= (String) request.getSession().getAttribute("uname"); String uspwd=request.getParameter("uspwd2"); SqlSession sqlSession=GetSqlSession.CreateSqlSession(); LoginMapper loginMapper=sqlSession.getMapper(LoginMapper.class); loginMapper.updateByusname(usname,uspwd); response.getWriter().write("修改成功"); response.getWriter().close(); sqlSession.close(); } }
5.usliulan.jsp(顾客浏览房产信息页面)
<%@ page import="org.apache.ibatis.session.SqlSession" %> <%@ page import="com.xxxx.util.GetSqlSession" %> <%@ page import="com.xxxx.mapper.HouseMapper" %> <%@ page import="com.xxxx.entity.House" %> <%@ page import="com.xxxx.mapper.UserMapper" %> <%@ page import="com.xxxx.entity.User" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/29 Time: 13:05 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>usliulan.jsp</title> </head> <%--顾客浏览房产信息--%> <body> <table align="center" width="800"> <tr> <td>房产编号</td><td>户型</td><td>房产地址</td><td>建造年份</td><td>建造面积</td><td>销售报价</td><td>销售状态</td><td>操作</td> </tr> <% SqlSession sqlSession= GetSqlSession.CreateSqlSession(); UserMapper userMapper=sqlSession.getMapper(UserMapper.class); User user=userMapper.selectByusname(request.getParameter("usname")); HouseMapper houseMapper=sqlSession.getMapper(HouseMapper.class); House[] houses=houseMapper.selectAllus(); for (House house:houses) { %> <tr> <td><%=house.getHoid()%></td><td><%=house.getHotype()%></td><td><%=house.getHoaddress()%></td><td><%=house.getHoyear()%></td><td><%=house.getHoarea()%></td><td><%=house.getHosale()%></td><td><%=house.getHostatus()%></td> <td><a href="usliulanServlet?hoid=<%=house.getHoid()%>&uid=<%=user.getUsid()%>">交易</a></td> </tr> <% } %> </table> </body> </html>
6.usliulanServlet(顾客购买房产Servlet)
package com.xxxx.servlet; import com.xxxx.mapper.HouseMapper; import com.xxxx.util.GetSqlSession; import org.apache.ibatis.session.SqlSession; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet("/usliulanServlet") public class usliulanServlet extends HttpServlet { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); String uid= request.getParameter("uid"); String hoid= request.getParameter("hoid"); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); HouseMapper houseMapper=sqlSession.getMapper(HouseMapper.class); houseMapper.updateStaByhoid(hoid,uid); response.getWriter().write("交易提交成功"); response.getWriter().close(); sqlSession.close(); } }
7.HouseMapper .java(接口类)
package com.xxxx.mapper; import com.xxxx.entity.House; import org.apache.ibatis.annotations.Param; public interface HouseMapper { void add(House house); House[] selectBy(House house); House selectByhoid(String hoid); House[] selectAll(); void updateByhoidagid(@Param("hoid") String hoid,@Param("aid") String aid); void updateByhoid(String hoid); House[] selectAllus(); void updateStaByhoid(@Param("hoid") String hoid, @Param("uid") String uid); }
8.HouseMapper.xml
<?xml version="1.0" encoding="UTF-8"?> <!--<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"--> <!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <!-- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"--> <!-- version="4.0">--> <!--</web-app>--> <!DOCTYPE mapper PUBLIC "-//mybatis.org/DTD Mapper 3.0" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!--namespace:命名空间--> <mapper namespace = "com.xxxx.mapper.HouseMapper"> <insert id="add"> insert into house (hoid,hotype,hoaddress,hoyear,hoarea,hosale,hostatus) values (#{hoid},#{hotype},#{hoaddress},#{hoyear},#{hoarea},#{hosale},#{hostatus}); </insert> <update id="updateByhoidagid"> update house set aid =#{aid},hostatus="待售" where hoid=#{hoid}; </update> <update id="updateByhoid"> update house set hostatus="停售" where hoid=#{hoid}; </update> <update id="updateStaByhoid"> update house set hostatus ="意向",uid=#{uid} where hoid=#{hoid}; </update> <select id="selectBy" resultType="com.xxxx.entity.House"> select * from house <where> <if test="hotype !=null and hosale!=''"> and hotype=#{hotype} </if> <if test="hoaddress!=null and hoaddress!=''"> and hoaddress=#{hoaddress} </if> <if test="hoyear!=null and hoyear!=''"> and hoyear=#{hoyear} </if> <if test="hoarea!=null and hoarea!=''"> and hoarea=#{hoarea} </if> <if test="hosale!=null and hosale!=''"> and hosale=#{hosale} </if> </where> </select> <select id="selectByhoid" resultType="com.xxxx.entity.House"> select * from house where hoid=#{hoid}; </select> <select id="selectAll" resultType="com.xxxx.entity.House"> select * from house; </select> <select id="selectAllus" resultType="com.xxxx.entity.House"> select * from house where hostatus="在售"; </select> </mapper>
9.UserMapper.java(接口类)
package com.xxxx.mapper; import com.xxxx.entity.User; public interface UserMapper { User[] selectusstatus(String usstatus); User selectByusidnum(String usidnum); void updateusstatus(String usidnum); void register(User user); User selectByusname(String usname); }
10.UserMapper.xml
<?xml version="1.0" encoding="UTF-8"?> <!--<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"--> <!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <!-- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"--> <!-- version="4.0">--> <!--</web-app>--> <!DOCTYPE mapper PUBLIC "-//mybatis.org/DTD Mapper 3.0" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!--namespace:命名空间--> <mapper namespace = "com.xxxx.mapper.UserMapper"> <insert id="register"> insert into user(usidnum,usname,ussex,usphone,usaddress,usstatus) values (#{usidnum},#{usname},#{ussex},#{usphone},#{usaddress},"0"); </insert> <update id="updateusstatus"> update user set usstatus = "1" where usidnum=#{usidnum}; </update> <select id="selectusstatus" resultType="com.xxxx.entity.User"> select * from user where usstatus=#{usstatus}; </select> <select id="selectByusidnum" resultType="com.xxxx.entity.User"> select * from user where usidnum=#{usidnum}; </select> <select id="selectByusname" resultType="com.xxxx.entity.User"> select * from user where usname=#{usname}; </select> </mapper>
11.LoginMapper.java(接口类)
package com.xxxx.mapper; import com.xxxx.entity.Login; import org.apache.ibatis.annotations.Param; public interface LoginMapper { Login selectByunametype(@Param("uname") String uname, @Param("type") String type); void updateByuname(String uname); Login selectByusname(String usname); void updateByusname(@Param("usname") String usname,@Param("uspwd") String uspwd); }
12.LoginMapper.xml
<?xml version="1.0" encoding="UTF-8"?> <!--<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"--> <!-- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"--> <!-- xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"--> <!-- version="4.0">--> <!--</web-app>--> <!DOCTYPE mapper PUBLIC "-//mybatis.org/DTD Mapper 3.0" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!--namespace:命名空间--> <mapper namespace = "com.xxxx.mapper.LoginMapper"> <update id="updateByuname"> update login01 set upwd = "123456" where uname=#{uname}; </update> <update id="updateByusname"> update login01 set upwd =#{uspwd} where uname=#{usname} and type="顾客"; </update> <select id="selectByunametype" resultType="com.xxxx.entity.Login"> select * from login01 where type=#{type} and uname=#{uname}; </select> <select id="selectByusname" resultType="com.xxxx.entity.Login"> select * from login01 where type="顾客" and uname=#{usname}; </select> </mapper>