房产信息管理系统--系统管理员功能实现
房产信息管理系统--系统管理员功能实现
总实现:test房产信息管理系统 - yuanse - 博客园 (cnblogs.com)
相关的文件:
房产信息管理系统--配置文件+工具类+实体类+登录选择页面+登录校验 - yuanse - 博客园 (cnblogs.com)
这一部分主要要注意:查询房产中,可以以很多种方式查询,比如说4种查询,可以只输入了一种查询条件,也可以输入多种查询条件:要处理为空的条件,还有全部为空的条件,因为全部为空会在查询的时候出现错误(按照我的那种写法);Servlet和mapper中都需要注意
1.admin.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>admin.jsp</title> </head> <%--系统管理者功能页 其中房产授权和停售房产都要先查看所有房产信息然后点击地址再进行不同的操作,可以再后面再分开操作 --%> <body> <a href="addho.jsp">新添房产信息</a><br> <a href="shouho.jsp">房产授权</a><br> <a href="shouho.jsp">停售房产</a><br> <a href="selectho.jsp">查询房产</a><br> <a href="addus.jsp">顾客审核</a><br> <a href="addag.jsp">新增房产经理人</a><br> <a href="upupwd.jsp">密码重置</a> </body> </html>
2.addho.jsp(添加房产信息)
<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/19 Time: 20:33 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>addho.jsp</title> </head> <body> <table align="center" border="1" width="800"> <form action="addhoServlet" method="post" id="addhoForm"> <tr> <td>房产编号</td> <td><input type="text" name="hoid" id="hoid"> </td> </tr> <tr> <td>户型</td> <td> <input type="radio" name="hotype" value="四室两厅">四室两厅<br> <input type="radio" name="hotype" value="四室一厅">四室一厅<br> <input type="radio" name="hotype" value="三室两厅">三室两厅<br> <input type="radio" name="hotype" value="三室一厅">三室一厅<br> <input type="radio" name="hotype" value="两室两厅">两室两厅<br> <input type="radio" name="hotype" value="两室一厅">两室一厅<br> </td> </tr> <tr> <td>房产地址</td> <td><input type="text" name="hoaddress" id="hoaddress"> </td> </tr> <tr> <td>建造年份</td> <td><input type="text" name="hoyear"></td> </tr> <tr> <td>建造面积</td> <td><input type="text" name="hoarea"></td> </tr> <tr> <td>销售报价</td> <td><input type="text" name="hosale"></td> </tr> <tr> <td>销售状态</td> <td> <select name="hostatus"> <option value="在售" selected>在售</option> <option value="待售">待售</option> <option value="意向">意向</option> <option value="售出">售出</option> <option value="停售">停售</option> </select> </td> </tr> <tr align="center"> <td colspan="2"><button>添加</button></td> </tr> </form> </table> </body> </html>
3.addhoServlet(添加房产信息Servlet)
package com.xxxx.servlet; import com.xxxx.entity.House; 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("/addhoServlet") public class addhoServlet 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 hoid =request.getParameter("hoid");//房子ID String hotype =request.getParameter("hotype") ;//户型 String hoaddress=request.getParameter("hoaddress") ;//房地址 String hoyear =request.getParameter("hoyear") ;//建造年份 String hoarea =request.getParameter("hoarea") ;//面积 String hosale =request.getParameter("hosale") ;//销售价格 String hostatus =request.getParameter("hostatus") ;//销售状态 House house=new House(hoid,hotype,hoaddress,hoyear,hoarea,hosale,hostatus); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); HouseMapper houseMapper=sqlSession.getMapper(HouseMapper.class); houseMapper.add(house); response.getWriter().write("添加房产信息成功"); response.getWriter().close(); sqlSession.close(); } }
4.shouho.jsp(房产授权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" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/19 Time: 22:57 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>shouho.jsp</title> </head> <%--房产授权:浏览所有的在售房产信息,显示序号、地址、价格,点击地址可看详情--%> <body> <table align="center" width="800" border="1"> <tr> <td>房产编号</td><td>房产地址</td><td>销售报价</td><td>销售状态</td> </tr> <% SqlSession sqlSession= GetSqlSession.CreateSqlSession(); HouseMapper houseMapper=sqlSession.getMapper(HouseMapper.class); House[] houses=houseMapper.selectAll(); for (House house:houses) { %> <tr><td><%=house.getHoid()%></td><td><a href="selecthoone.jsp?hoid=<%=house.getHoid()%>"><%=house.getHoaddress()%><a/></td><td><%=house.getHosale()%></td></tr> <% } %> </table> </body> </html>
5.selecthoone.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" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/19 Time: 23:19 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>selecthoone.jsp</title> </head> <%--点击地址,查询房户详情信息--%> <body> <table align="center" width="800" border="1"> <% String hoid=request.getParameter("hoid"); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); HouseMapper houseMapper=sqlSession.getMapper(HouseMapper.class); House house=houseMapper.selectByhoid(hoid); request.getSession().setAttribute("hoid",hoid);//向Servlet传递房产信息 %> <tr> <td>房产编号</td><td>户型</td><td>房产地址</td><td>建造年份</td><td>建造面积</td><td>销售报价</td><td>销售状态</td><td>操纵</td> </tr> <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="tinghoServlet?hoid=<%=hoid%>">停售</a> </td></tr> </table> <form method="post" action="selecthoone"> 输入房产经理姓名:<input type="text" name="agname"><br> <span style="font-size: 16px;color: red">${msg}</span> <button>授权</button> </form> </body> </html>
6.selecthoone.java(房产授权:添加经理)
package com.xxxx.servlet; import com.xxxx.entity.Agent; import com.xxxx.mapper.AgentMapper; 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; /** * 房产授权中,需要查询是否有这个经理 * 无-->返回错误信息 * 有-->在该房产中 aid=agid(把经理的id添加到房产信息中),并且把房产状态信息改成“待售”状态 */ @WebServlet("/selecthoone") public class selecthoone 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 agname=request.getParameter("agname"); String hoid= (String) request.getSession().getAttribute("hoid"); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); AgentMapper agentMapper=sqlSession.getMapper(AgentMapper.class); Agent agent=agentMapper.selectByagname(agname); if(agent==null){ //第一步的写法会出现问题,就是跳转回去之后,没有hoid等数据对房产信息进行查询,所以我直接在页面提示错误信息,就不跳转回去了 // request.setAttribute("msg","房产经纪人信息不存在"); // request.getRequestDispatcher("selecthoone.jsp").forward(request,response); response.getWriter().write("房产经纪人信息不存在"); response.getWriter().close(); } else{//房产经理的名字存在,进行授权,房产状态为:待售 HouseMapper houseMapper=sqlSession.getMapper(HouseMapper.class); houseMapper.updateByhoidagid(hoid,agent.getAgid()); response.getWriter().write("更新成功"); response.getWriter().close(); } sqlSession.close(); } }
7.tinghoServlet(停售房产)
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("/tinghoServlet") public class tinghoServlet 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 hoid=request.getParameter("hoid"); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); HouseMapper houseMapper=sqlSession.getMapper(HouseMapper.class); houseMapper.updateByhoid(hoid); response.getWriter().write("房产状态更新成功"); response.getWriter().close(); sqlSession.close(); } }
8.selectho.jsp(查询房产)
<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/19 Time: 20:33 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>selectho.jsp</title> </head> <%--管理员查询房产信息--%> <body> <table align="center" width="400" > <form method="post" action="selecthoServlet"> <tr> <td>户型</td> <td><input type="text" name="hotype"> </td> </tr> <tr> <td>地址</td> <td><input type="text" name="hoaddress"> </td> </tr> <tr> <td>建造年份</td> <td><input type="text" name="hoyear"> </td> </tr> <tr> <td>建造面积</td> <td><input type="text" name="hoarea"> </td> </tr> <tr> <td>销售报价</td> <td><input type="text" name="hosale"> </td> </tr> <tr align="center"> <td colspan="2"><span style="font-size: 16px;color: red">${msg}</span> </td> </tr> <tr align="center"> <td colspan="2"><button>查询</button></td> </tr> </form> </table> </body> </html>
9.selecthoServlet(查询房产Servlet)
package com.xxxx.servlet; import com.xxxx.entity.House; 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; /** * 可以按照户型、地址、建造年份、建造面积,销售报价五个条件进行综合查询 * -->问题在于,不知道哪一个为空,在mapper中写的时候需要动态查询 */ @WebServlet("/selecthoServlet") public class selecthoServlet 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 hotype=request.getParameter("hotype"); String hoaddress=request.getParameter("hoaddress"); String hoyear=request.getParameter("hoyear"); String hoarea=request.getParameter("hoarea"); String hosale=request.getParameter("hosale"); System.out.println("hotype "+hotype+" hoaddress "+hoaddress+" hoyear "+hoyear+" hoarea "+hoarea+" hosale "+hosale); if((hotype==null||"".equals(hotype.trim()))&&(hoaddress==null||"".equals(hoaddress.trim()))&&(hoyear==null||"".equals(hoyear.trim()))&&(hoarea==null||"".equals(hoarea.trim()))&&(hosale==null||"".equals(hosale.trim()))){ request.setAttribute("msg","请填入查询信息!!"); request.getRequestDispatcher("selectho.jsp").forward(request,response); } House house=new House(); house.setHotype(hotype);house.setHoaddress(hoaddress);house.setHoyear(hoyear);house.setHoarea(hoarea);house.setHosale(hosale); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); HouseMapper houseMapper=sqlSession.getMapper(HouseMapper.class); House[] house1=houseMapper.selectBy(house); if(house1==null){ request.setAttribute("msg","不存在该房产信息"); request.getRequestDispatcher("selectho.jsp").forward(request,response); } else { request.setAttribute("house",house1); request.getRequestDispatcher("selecthors.jsp").forward(request,response); } sqlSession.close(); } }
10.selecthors.jsp(房产查询结果显示)
<%@ page import="com.xxxx.entity.House" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/19 Time: 22:02 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>selecthors.jsp</title> </head> <%--管理员查询房产信息显示::结果--%> <body> <table align="center" width="800" border="1"> <tr> <td>房产编号</td><td>户型</td><td>房产地址</td><td>建造年份</td><td>建造面积</td><td>销售报价</td><td>销售状态</td> </tr> <% House[] houses= (House[]) request.getAttribute("house"); 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></tr> <% } %> </table> </body> </html>
11.addus.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/19 Time: 20:33 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>addus.jsp</title> </head> <%--管理员:顾客审核,再顾客表中,找到usstatus=0的顾客,意味着注册但没审核通过的,点击顾客姓名,可以查询详信息--%> <body> <table width="400" align="center"> <tr> <td>姓名</td> </tr> <% SqlSession sqlSession= GetSqlSession.CreateSqlSession(); UserMapper userMapper=sqlSession.getMapper(UserMapper.class); User[] users=userMapper.selectusstatus("0"); for (User user:users){ %> <tr> <td><a href="addus2.jsp?usidnum=<%=user.getUsidnum()%>"><%=user.getUsname()%></a></td> </tr> <% } %> </table> </body> </html>
12.addus2.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/26 Time: 19:01 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>addus2.jsp</title> </head> <%--管理员审核顾客中:显示详细的顾客信息--%> <body> <table width="800" align="center"> <% String usidnum=request.getParameter("usidnum");//身份证号 SqlSession sqlSession= GetSqlSession.CreateSqlSession(); UserMapper userMapper=sqlSession.getMapper(UserMapper.class); User user=userMapper.selectByusidnum(usidnum); %> <tr> <td>顾客ID</td><td>姓名</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><td><a href="addusServlet?usidnum=<%=user.getUsidnum()%>">通过审核</a></td> </tr> </table> </body> </html>
13.addusServlet(顾客审核Servlet:向数据库中修改状态审核成功为1)
package com.xxxx.servlet; import com.xxxx.mapper.UserMapper; 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; /** * 管理员审核顾客功能:通过审核,把user表中的usstatus设置为1,说明审核通过了 */ @WebServlet("/addusServlet") public class addusServlet 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 usidnum=request.getParameter("usidnum"); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); UserMapper userMapper=sqlSession.getMapper(UserMapper.class); userMapper.updateusstatus(usidnum); response.getWriter().write("审核成功"); response.getWriter().close(); sqlSession.close(); } }
14.addag.jsp(新添房产经理信息jsp页面)
<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/19 Time: 20:34 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>addag.jsp</title> </head> <%--新添房产经理信息--%> <body> <table align="center" border="1" width="800"> <form action="addagServlet" method="post" id="addagForm"> <tr> <td>工号</td> <td><input type="text" name="agid" id="agid"> </td> </tr> <tr> <td>姓名</td> <td><input type="text" name="agname" id="agname"> </td> </tr> <tr> <td>家庭住址</td> <td><input type="text" name="agaddress" id="agaddress"> </td> </tr> <tr> <td>手机</td> <td><input type="text" name="agphone" id="agphone"> </td> </tr> <tr align="center"> <td colspan="2"><button>添加</button></td> </tr> </form> </table> </body> </html>
15.addagServlet(添加经理信息Servlet)
package com.xxxx.servlet; import com.xxxx.entity.Agent; import com.xxxx.mapper.AgentMapper; 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("/addagServlet") public class addagServlet 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 agid =request.getParameter("agid");//经理id String agname =request.getParameter("agname");//经理姓名 String agaddress=request.getParameter("agaddress");//经理地址 String agphone =request.getParameter("agphone") ;//经理电话 Agent agent=new Agent(agid,agname,agaddress,agphone); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); AgentMapper agentMapper=sqlSession.getMapper(AgentMapper.class); agentMapper.add(agent); response.getWriter().write("添加经理信息成功"); response.getWriter().close(); sqlSession.close(); } }
16.upupwd.jsp(密码重置jsp页面)
<%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/19 Time: 20:34 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>upupwd.jsp</title> </head> <%--管理员密码重置 工号查询->点击重置:123456 --%> <body> <form action="upupwdServlet" method="post"> 输入房产经理的工号id:<input type="text" name="agid"><br> <span style="font-size: 16px;color: red" name="msg">${msg}</span><br> <button>查询</button> </form> </body> </html>
17.upupwdServlet(密码重置:判断工号是否存在Servlet)
package com.xxxx.servlet; import com.xxxx.entity.Agent; import com.xxxx.mapper.AgentMapper; 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("/upupwdServlet") public class upupwdServlet 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 agid=request.getParameter("agid"); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); AgentMapper agentMapper=sqlSession.getMapper(AgentMapper.class); Agent agent=agentMapper.selectByagid(agid); if(agent==null){ request.setAttribute("msg","工号不存在"); request.getRequestDispatcher("upupwd.jsp").forward(request,response); }else{ request.getSession().setAttribute("agent",agent); response.sendRedirect("upupwdsel.jsp"); } sqlSession.close(); } }
18.upupwdsel.jsp(密码重置:显示要重置的工号的详细信息)
<%@ page import="com.xxxx.entity.Agent" %><%-- Created by IntelliJ IDEA. User: 22466 Date: 2022/11/26 Time: 17:16 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>upupwdsel.jsp</title> </head> <%--管理员重置密码,查到工号对应的经理信息,点击重置可以重置密码--%> <body> <table align="center" border="1" width="800"> <tr> <td>工号</td><td>姓名</td><td>家庭住址</td><td>手机</td><td>密码重置</td> </tr> <tr> <td>${agent.getAgid()}</td><td>${agent.getAgname()}</td><td>${agent.getAgaddress()}</td><td>${agent.getAgphone()}</td><td><a href="upupwdServlet2?uname=${agent.getAgname()}">密码重置</a></td> </tr> </table> </body> </html>
19.upupwdServlet2(密码重置:密码重置Servlet)
package com.xxxx.servlet; 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("/upupwdServlet2") public class upupwdServlet2 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 uname=request.getParameter("uname"); SqlSession sqlSession= GetSqlSession.CreateSqlSession(); LoginMapper loginMapper=sqlSession.getMapper(LoginMapper.class); loginMapper.updateByuname(uname); response.getWriter().write("密码重置成功"); response.getWriter().close(); sqlSession.close(); } }
20.AgentMapper.java(接口)
package com.xxxx.mapper; import com.xxxx.entity.Agent; public interface AgentMapper { void add(Agent agent); Agent selectByagname(String agname); Agent selectByagid(String agid); }
21.AgentMapper.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.AgentMapper"> <insert id="add"> insert into agent (agid,agname,agaddress,agphone) values (#{agid},#{agname},#{agaddress},#{agphone}); </insert> <select id="selectByagname" resultType="com.xxxx.entity.Agent"> select * from agent where agname=#{agname}; </select> <select id="selectByagid" resultType="com.xxxx.entity.Agent"> select * from agent where agid=#{agid}; </select> </mapper>
22.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); }
23.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> <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> </mapper>
24.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); }
25.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> <select id="selectByunametype" resultType="com.xxxx.entity.Login"> select * from login01 where type=#{type} and uname=#{uname}; </select> </mapper>
26.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); }
27.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"> <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> </mapper>