房屋管理系统简单Damo
1.登录页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
<script>
$(function () {
$("#submit").click(function () {
var username = $("input:eq(0)");
var password = $("input:eq(1)");
var msg = ""
if ($.trim(username.val()) == "") {
msg = "用户名不能为空!";
username.focus();
} else if ($.trim(password.val()) == "") {
msg = "密码不能为空!";
password.focus();
}
if (msg != "") {
alert(msg);
} else {
// 获取表单中的参数
var params = $("#form").serialize();
// 发送登录的异步请求
$.ajax({
url: "user/login",
data: params,
success: function (data) {
if (data == "ok") {
window.location.href = "house/selectAll"
} else {
alert("账号或密码错误");
}
}
})
}
});
// 为document绑定onkeydown事件监听是否按了回车键
$(document).keydown(function (event) {
if (event.keyCode === 13) { // 按了回车键
$("#submit").trigger("click");
}
});
});
</script>
</head>
<body>
<form id="form">
用户名:<input name="userName"><br>
密 码:<input name="userPwd"><br>
<input value="登录" id="submit" type="button">
</form>
</body>
</html>
2展示页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'house.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
<script type="text/javascript">
$(function() {
$("#che").click(function() {
if (this.checked) {
$(".in").prop("checked", true);
} else {
$(".in").prop("checked", false);
}
});
$("#del").click(function() {
if (confirm("是否删除")) {
var ids = [];
$(".in").each(function() {
ids.push($(this).val());
});
$.post("house/del", {
"ids" : ids.join(",")
}, function() {
location.reload();
});
}
});
})
</script>
</head>
<body>
<form action="house/selectHouseName">
<input type="button" value="添加房屋信息"
οnclick="window.location.href='house/selectPerson'">
<input
type="button" value="删除房屋 信息" id="del">
<input type="submit" value="搜索">
<select name="pid">
<c:forEach items="${listPerson }" var="l">
<option value="${l.pid}">${l.personName}</option>
</c:forEach>
</select>
</form>
<table border="1">
<tr>
<td><input type="checkbox" id="che"></td>
<td>房屋名称</td>
<td>房屋图片</td>
<td>房屋单价</td>
<td>房屋面积</td>
<td>房屋总价</td>
<td>购买日期</td>
<td>所属户主</td>
<td>操作</td>
</tr>
<c:forEach items="${listHouse.list }" var="l">
<tr>
<td><input type="checkbox" value="${l.hid}" class="in"></td>
<td>${l.houseName }</td>
<td><img alt="" src="data:images/${l.houserImg}" width="30" height="30"></td>
<td>${l.housePrice }</td>
<td>${l.houseArea }</td>
<td>${l.totalCount }</td>
<td><f:formatDate value="${l.buyDate}" /></td>
<td>${l.person.personName}</td>
<td><span style="color:maroon;" οnclick="window.location.href='house/selectById?id=${l.hid}'">修改房屋信息</span></td>
</tr>
</c:forEach>
</table>
<button
οnclick="window.location.href='${url}?pageNo=${listHouse.prePage}'">上一页</button>
<c:forEach begin="1" end="${listHouse.lastPage}" var="l">
<button οnclick="window.location.href='${url}?pageNo=${l}'">${l}</button>
</c:forEach>
<button
οnclick="window.location.href='${url}?pageNo=${listHouse.nextPage}'">下一页</button>
</body>
</html>
3添加页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'add.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
<script type="text/javascript">
$(function() {
var s0 = false;
var s1 = false;
var s2 = false;
var s3 = false;
$("input:eq(0)").blur(function() {
var houseName = $(this).val();
$("#id0").empty();
if (houseName == null || houseName == "") {
s0 = false;
$(".c:eq(0)").after("<span id='id0'>输入为空</span>");
} else {
$.ajax({
url : "house/selectByName",
data : {
"houseName" : houseName
},
success : function(data) {
if (data == "ok") {
s0 = true;
$(".c:eq(0)").after("<span id='id0'>输入正确</span>");
} else {
s0 = false;
$(".c:eq(0)").after("<span id='id0'>用户已存在</span>");
}
}
});
}
});
$("input:eq(1)").blur(function() {
var name = $(this).val();
$("#id1").empty();
if (name == null || name == "") {
s1 = false;
$(".c:eq(1)").after("<span id='id1'>输入为空</span>");
} else {
s1 = true;
$(".c:eq(1)").after("<span id='id1'>输入正确</span>");
}
});
$("input:eq(2)").blur(function() {
var name = $(this).val();
$("#id2").empty();
if (name == null || name == "") {
s2 = false;
$(".c:eq(2)").after("<span id='id2'>输入为空</span>");
} else {
s2 = true;
$(".c:eq(2)").after("<span id='id2'>输入正确</span>");
}
});
$("input:eq(3)").blur(function() {
var name = $(this).val();
$("#id3").empty();
if (name == null || name == "") {
s3 = false;
$(".c:eq(3)").after("<span id='id3'>请上传图片</span>");
} else {
s3 = true;
$(".c:eq(3)").after("<span id='id3'>上传成功</span>");
}
});
$(":submit").click(function() {
if (s0 & s1 & s2 & s3) {
$(this).submit();
} else {
return false;
}
});
});
</script>
</head>
<body>
<form action="house/addHouse" enctype="multipart/form-data" method="post">
房屋名称:<input name="houseName"><span class="c"></span><br>
房屋单价:<input name="housePrice"><span class="c"></span><br>
房屋面积:<input name="houseArea"><span class="c"></span><br>
房屋图片:<input type="file" name="file"><span class="c"></span><br>
房屋户主:<select name="person.pid">
<c:forEach items="${list}" var="l">
<option value="${l.pid}">${l.personName}</option>
</c:forEach>
</select><br>
<input type="submit" value="添加" >
</form>
</body>
</html>
4.修改页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'add.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="js/jquery-2.1.0.js"></script>
</head>
<body>
<form action="house/updateHouse" enctype="multipart/form-data" method="post">
<input name="hid" value="${house.hid}" hidden>
房屋名称:<input name="houseName" value="${house.houseName}"><span class="c"></span><br>
房屋单价:<input name="housePrice" value="${house.housePrice}"><span class="c"></span><br>
房屋面积:<input name="houseArea" value="${house.houseArea}"><span class="c"></span><br>
房屋图片:<input type="file" name="file" ><%-- <img src="${house.houseImg}"> --%><span class="c"></span><br>
房屋户主:<select name="person.pid">
<c:forEach items="${list}" var="l">
<c:choose>
<c:when test="${l.pid==house.person.pid}">
<option value="${l.pid}" selected="selected">${l.personName}</option>
</c:when>
<c:otherwise>
<option value="${l.pid}">${l.personName}</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select><br>
<input type="submit" value="修改" >
</form>
</body>
</html>
控制器
package com.bw.controller;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.xml.ws.spi.http.HttpContext;
import org.apache.commons.io.FileUtils;
import org.jboss.weld.servlet.ServletApiAbstraction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import redis.clients.jedis.Jedis;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.bw.pojo.House;
import com.bw.pojo.Person;
import com.bw.pojo.PersonExample;
import com.bw.service.HouseService;
import com.bw.service.PersonService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@Controller
@RequestMapping("house")
public class HouseController {
@Autowired
private HouseService houseService;
@Autowired
private PersonService personService;
@SuppressWarnings("resource")
@RequestMapping("selectAll")
public ModelAndView selectAll(ModelAndView modelAndView,
PersonExample example, Integer pageNo, Integer pageSize) {
Jedis jedis = new Jedis("192.168.134.10", 6379);
String string = jedis.get("listPerson");
List<Person> listPerson;
if (string == null) {
listPerson = personService.selectByExample(example);
jedis.set("listPerson", JSON.toJSONString(listPerson));
} else {
listPerson = JSON.parseArray(string, Person.class);
}
modelAndView.addObject("listPerson", listPerson);
if (pageNo == null || pageNo <= 0) {
pageNo = 1;
}
if (pageSize == null) {
pageSize = 2;
}
PageHelper.startPage(pageNo, pageSize);
List<House> listHouse = houseService.selectAll();
PageInfo<House> list = new PageInfo<House>(listHouse);
modelAndView.addObject("url", "house/selectAll");
modelAndView.addObject("listHouse", list);
modelAndView.setViewName("house");
return modelAndView;
}
@RequestMapping("selectPerson")
public ModelAndView selectPerson(ModelAndView modelAndView,
PersonExample example) {
Jedis jedis = new Jedis("192.168.134.10", 6379);
String string = jedis.get("listPerson");
List<Person> listPerson;
if (string == null) {
listPerson = personService.selectByExample(example);
jedis.set("listPerson", JSON.toJSONString(listPerson));
} else {
listPerson = JSON.parseArray(string, Person.class);
}
modelAndView.addObject("list", listPerson);
modelAndView.setViewName("add");
return modelAndView;
}
@RequestMapping("selectByName")
@ResponseBody
public String selectByName(String houseName) {
House list = houseService.selectByHouseName(houseName);
if (list == null) {
return "ok";
} else {
return "error";
}
}
@RequestMapping("addHouse")
public String addHouse(House house, MultipartFile file,
HttpServletRequest request) throws IllegalStateException,
IOException {
String filename = file.getOriginalFilename();
String suffixName = filename.substring(filename.lastIndexOf("."));
filename = UUID.randomUUID() + suffixName;
// File file = new
// File("D:\\javawab\\apache-tomcat-7.0.62\\webapps\\zyc20171025\\images");
String realPath = request.getSession().getServletContext()
.getRealPath("/images");
File filePath = new File(realPath + File.separator + filename);
file.transferTo(filePath);
house.setBuyDate(new Date());
house.setHouserImg(filename);
house.setTotalCount(house.getHouseArea() * house.getHousePrice());
houseService.addHouse(house);
return "redirect:/house/selectAll";
}
@RequestMapping("del")
@ResponseBody
public String del(String ids){
houseService.deleteByIds(ids) ;
return "ok";
}
private int i;
@RequestMapping("selectHouseName")
public ModelAndView selectHouseName(ModelAndView modelAndView,
PersonExample example, Integer pageNo, Integer pageSize,Integer pid) {
if (pid!=null) {
i=pid;
}
Jedis jedis = new Jedis("192.168.134.10", 6379);
String string = jedis.get("listPerson");
List<Person> listPerson;
if (string == null) {
listPerson = personService.selectByExample(example);
jedis.set("listPerson", JSON.toJSONString(listPerson));
} else {
listPerson = JSON.parseArray(string, Person.class);
}
modelAndView.addObject("listPerson", listPerson);
if (pageNo == null || pageNo <= 0) {
pageNo = 1;
}
if (pageSize == null) {
pageSize = 2;
}
PageHelper.startPage(pageNo, pageSize);
List<House> listHouse = houseService.selectByPId(i);
PageInfo<House> list = new PageInfo<House>(listHouse);
modelAndView.addObject("url", "house/selectHouseName");
modelAndView.addObject("listHouse", list);
modelAndView.setViewName("house");
return modelAndView;
}
@RequestMapping("selectById")
public ModelAndView selectById(ModelAndView modelAndView,Integer id,PersonExample example){
Jedis jedis = new Jedis("192.168.134.10", 6379);
String string = jedis.get("listPerson");
List<Person> listPerson;
if (string == null) {
listPerson = personService.selectByExample(example);
jedis.set("listPerson", JSON.toJSONString(listPerson));
} else {
listPerson = JSON.parseArray(string, Person.class);
}
House house = houseService.selectById(id);
modelAndView.addObject("list", listPerson);
modelAndView.addObject("house", house);
modelAndView.setViewName("update");
return modelAndView;
}
@RequestMapping("updateHouse")
public String updateHouse(House house,MultipartFile file,HttpServletRequest request) throws IllegalStateException, IOException{
String filename = file.getOriginalFilename();
String suffixName = filename.substring(filename.lastIndexOf("."));
filename = UUID.randomUUID() + suffixName;
// File file = new
// File("D:\\javawab\\apache-tomcat-7.0.62\\webapps\\zyc20171025\\images");
String realPath = request.getSession().getServletContext()
.getRealPath("/images");
File filePath = new File(realPath + File.separator + filename);
file.transferTo(filePath);
house.setTotalCount(house.getHousePrice()*house.getHouseArea());
house.setHouserImg(filename);
houseService.updateHouse(house);
return "redirect:/house/selectAll";
}
}
4houseMapper
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.bw.dao.HouseMapper" >
<resultMap id="rm" type="com.bw.pojo.House" >
<id column="hid" property="hid" jdbcType="INTEGER" />
<result column="house_name" property="houseName" jdbcType="VARCHAR" />
<result column="houser_img" property="houserImg" jdbcType="VARCHAR" />
<result column="house_area" property="houseArea" jdbcType="INTEGER" />
<result column="house_price" property="housePrice" jdbcType="DOUBLE" />
<result column="total_count" property="totalCount" jdbcType="DOUBLE" />
<result column="buy_date" property="buyDate" jdbcType="DATE" />
<association property="person" javaType="person">
<id column="pid" property="pid" jdbcType="INTEGER" />
<result column="person_name" property="personName" jdbcType="VARCHAR" />
</association>
</resultMap>
<select id="selectAll" resultMap="rm">
select * from house h,person p where h.person_id= p.pid
</select>
<select id="selectByName" parameterType="string" resultMap="rm">
select * from house h,person p where h.person_id= p.pid and p.person_name=#{value}
</select>
<select id="selectByHouseName" parameterType="string" resultMap="rm">
select * from house h,person p where h.person_id= p.pid and h.house_name=#{value}
</select>
<delete id="deleteByIds" parameterType="string">
delete from house where hid in (${value})
</delete>
<select id="selectById" parameterType="integer" resultMap="rm">
select * from house h,person p where h.person_id= p.pid and h.hid = #{value}
</select>
<select id="selectByPId" parameterType="integer" resultMap="rm">
select * from house h,person p where h.person_id= p.pid and h.person_id = #{value}
</select>
<update id="updateHouse" parameterType="house">
update house set house_name=#{houseName},houser_img=#{houserImg},house_area=#{houseArea},house_price=#{housePrice},total_count=#{totalCount},person_id=#{person.pid} where hid = #{hid}
</update>
<insert id="addHouse" parameterType="house">
insert into house(house_name,houser_img,house_area,house_price,total_count,buy_date,person_id) values(#{houseName},#{houserImg},#{houseArea},#{housePrice},#{totalCount},#{buyDate},#{person.pid});
</insert>
</mapper>
房屋管理系统简单Damo相关推荐
- 部署高校房屋管理系统可以实现哪些目标?
数图互通房产管理 随着技术的不断进步和升级,以及高校房屋建筑物数量的不断扩充,建立房屋资产管理信息系统进行信息化.数字化.图形化房屋资产管理已经是势在必行.数图互通自主研发的FMCenterV5.0平 ...
- 【Java】房屋管理系统
[Java]房屋管理系统 韩顺平老师关于房屋管理系统的讲解 我的思路 工具类实现读取整数,读取字符串,读取字符,读取Y/N等功能(这一部分直接抄老韩的代码) package houserent.uti ...
- 数图互通高校房屋管理系统具体管理范围
数图互通高校房屋管理系统的管理范围包括: 1.基础数据管理:对学校.校区.片区.建筑物.土地﹑楼层.房间.教职工.学生.房屋分类等基础数据进行管理,批量导入导出数据等. 2.校园电子地图:可在系统中建 ...
- 基于springboot2.0的易居二手房网站-房屋管理系统
基于springboot2.0的易居二手房网站-房屋管理系统-java二手房网站java房屋管理系统 1.包含源程序,数据库脚本.代码和数据库脚本都有详细注释. 2.课题设计仅供参考学习使用,可以在此 ...
- javaweb JAVA JSP房屋租赁管理系统房屋管理系统JSP网上租房系统JSP房产信息网站
javaweb JAVA JSP房屋租赁管理系统房屋管理系统JSP网上租房系统JSP房产信息网站房屋租赁系统房屋 常见的Javaweb题材有 理财系统,就业管理系统,汽车租赁,简易网盘,疫情数据查看, ...
- 招聘管理系统简单设计
基于Spring+Spring MVC的招聘管理系统简单设计 罗纳尔康 说明:这是一个学习过程中的小练习,其中涉及到知识也挺多的,所以做此文章来记录,并加深印象. 开发环境: Eclipse/MyEc ...
- javaweb JAVA JSP房屋租赁管理系统房屋管理系统JSP网上租房系统JSP房产信息网站房屋租赁系统房屋
javaweb JAVA JSP房屋租赁管理系统房屋管理系统JSP网上租房系统JSP房产信息网站房屋租赁系统房屋 常见的Javaweb题材有 理财系统,就业管理系统,汽车租赁,简易网盘,疫情数据查看, ...
- 车票管理系统java_JAVA车票管理系统(简单GUI).docx
JAVA车票管理系统(简单GUI) JAVA程序设计报告需求分析1.设计题目:车票管理系统用JAVA语言和数据结构知识设计设计车票管理系统.要求如下所述:一车站每天有n个发车班次,每个班次都有一个班次 ...
- 基于web端的房屋管理系统(附完整源码)
房屋中介管理系统是针对房产中介门店运营和日常管理,而由开发人员设计的一体化管理系统.在经过多年的发展,目前市面上种类繁多,但都趋向于同质化发展.为了解决功能的完善,还需要经过众多中介实际使用和测试,再 ...
- java实现简单控制台出租房屋管理系统
源代码及数据库获取链接: https://download.csdn.net/download/qq_45968259/12544000 目录 系统结构 系统功能分析 系统的类设计 系统功能实现 系统 ...
最新文章
- 从算法到硬件,一文读懂2019年 AI如何演进
- mongodb模糊查询包含特殊字符
- asp.net Forums 之HttpHandler和HttpModule
- elasticsearch高亮显示查询结果
- 《去哪网编程题》统计字符
- 小自考计算机专业代码,自学考试有关专业分类及其代码
- 性能测试流程-各阶段的工作
- H3 BPM MVC表单SheetAttachment控件使用NTKO打开附件(Word、Excel)
- 【Java基础教程】Java的输入输出
- 使用CentOS7搭建Nat64服务器实现IPv6网段访问IPv4地址
- c语言char储存字符串,在c语言中char型数据在内存中的储存形式为什么
- Win10下如何找到下载的主题壁纸,并提取图片
- sqlplus操作oracle
- c语言求解连续数列编程题,数列-题解(C语言代码)
- 如何爬取当当网畅销书排行榜信息? requests + pyquery
- 基于jsp+mysql+Spring+SpringMVC+mybatis的ssm框架个人博客系统多用户
- scipy 插值重采样
- 用人工智能判断红楼梦后40回是否是曹雪芹写的
- Comparison of Big Data OLAP DB : ClickHouse, Druid, and Pinot
- [币严区块链]数字货币交易所之以太坊(ETH)钱包对接(一) 以太坊Geth客户端安装...