SSM框架整合项目 :租房管理系统

使用ssm框架整合,oracle数据库

框架:

Spring

SpringMVC

MyBatis

SSM框架整合项目 :租房管理系统

导包:

1, spring

2, MyBatis

3, mybatis-spring

4, fastjson

5, aspectweaver----AspectJ框架

6, log4j-----打印日志信息

7, ojdbc6.jar

8, jstl.jar, standard.jar----标准标签库

9, commons-logging-1.2.jar

10,……

项目结构:

SSM框架整合项目 :租房管理系统

配置文件同前面:http://www.cnblogs.com/jiangwz/p/7674275.html

项目代码:

model:

 package com.hanqi.model;

 public class House {

     private Integer id;
private String keyword;
private String area;
private Integer squaremeter;
private Integer rent;
private String renttype;
private String housetype; public House(Integer id, String keyword, String area, Integer squaremeter, Integer rent, String renttype,
String housetype) {
super();
this.id = id;
this.keyword = keyword;
this.area = area;
this.squaremeter = squaremeter;
this.rent = rent;
this.renttype = renttype;
this.housetype = housetype;
} public House() {
super();
// TODO Auto-generated constructor stub
} public Integer getId() {
return id;
} public void setId(Integer id) {
this.id = id;
} public String getKeyword() {
return keyword;
} public void setKeyword(String keyword) {
this.keyword = keyword;
} public String getArea() {
return area;
} public void setArea(String area) {
this.area = area;
} public Integer getSquaremeter() {
return squaremeter;
} public void setSquaremeter(Integer squaremeter) {
this.squaremeter = squaremeter;
} public Integer getRent() {
return rent;
} public void setRent(Integer rent) {
this.rent = rent;
} public String getRenttype() {
return renttype;
} public void setRenttype(String renttype) {
this.renttype = renttype;
} public String getHousetype() {
return housetype;
} public void setHousetype(String housetype) {
this.housetype = housetype;
} @Override
public String toString() {
return "House [id=" + id + ", keyword=" + keyword + ", area=" + area + ", SQUAREMETER=" + squaremeter
+ ", rent=" + rent + ", renttype=" + renttype + ", housetype=" + housetype + "]";
} }

dao层:

 package com.hanqi.dao;

 import java.util.List;

 import com.hanqi.model.House;

 public interface HouseDao {

     List<House> selectAll();

     int inserthouse(House house);

     int delhouse(Integer id);

     int updatehouse(House house);

     List<House> selectinfo(House house);

 }

dao层实现方法:

 <?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.hanqi.dao.HouseDao"> <select id="selectAll" resultType="House">
select t.*from TABLE_HOUSE t
</select> <insert id="inserthouse" parameterType="House" useGeneratedKeys="true" keyProperty="id" keyColumn="id">
insert into TABLE_HOUSE values(test1.nextval,#{keyword},#{area},#{squaremeter},#{rent},#{renttype},#{housetype})
</insert> <delete id="delhouse" parameterType="Map">
delete TABLE_HOUSE t where t.id=#{id}
</delete> <update id="updatehouse" parameterType="Map">
update TABLE_HOUSE t set t.keyword=#{keyword},t.area=#{area},t.squaremeter=#{squaremeter},t.rent=#{rent},t.renttype=#{renttype},t.housetype=#{housetype} where t.id=#{id}
</update> <select id="selectinfo" resultType="House" parameterType="House">
select t.* from TABLE_HOUSE t
<where>
<if test="keyword!=null">
and t.keyword like #{keyword}
</if>
<if test="area!=null">
and t.area=#{area}
</if>
<if test="renttype!=null">
and t.renttype in #{renttype}
</if>
<if test="housetype!=null">
and t.housetype=#{housetype}
</if>
</where> </select>
</mapper>

controller控制器:

 package com.hanqi.controller;

 import java.util.ArrayList;
import java.util.List; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView; import com.alibaba.fastjson.JSONObject;
import com.hanqi.dao.HouseDao;
import com.hanqi.model.House; @Controller
@SessionAttributes("currentUser")
@RequestMapping("/house")
public class HouseController { @Autowired
private HouseDao houseDao; @ResponseBody
@RequestMapping("/selectAll")
public JSONObject selectAll() {
JSONObject jo = new JSONObject();
List<House> list = houseDao.selectAll();
jo.put("total", list.size());
jo.put("rows", list); return jo;
} @ResponseBody
@RequestMapping("/selectinfo")
public ModelAndView selectinfo(House house){ house.setKeyword("%"+house.getKeyword()+"%");
List<House> list = houseDao.selectinfo(house);
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("houselook3");
modelAndView.addObject("list",list); return modelAndView; } @ResponseBody
@RequestMapping("/selectAll1")
public ModelAndView selectAll1(Model model) {
//List<House> list = houseDao.selectAll();
//System.out.println(list); //model.addAttribute("list", list); ModelAndView mv = new ModelAndView("redirect:/houselook.jsp");
return mv; } @RequestMapping("/selectAll2")
public String selectAll2(Model model) {
List<House> list = houseDao.selectAll();
System.out.println(list);
model.addAttribute("list", list); return "houselook2";
} @ResponseBody
@RequestMapping("/addhouse")
public ModelAndView addhouse(House house) {
int i=houseDao.inserthouse(house); ModelAndView mv = new ModelAndView("redirect:/index.jsp");
return mv; } @ResponseBody
@RequestMapping("/delhouse")
public ModelAndView delhouse(Integer id) {
int i=houseDao.delhouse(id);
ModelAndView mv = new ModelAndView("redirect:/index.jsp");
return mv;
} @ResponseBody
@RequestMapping("/updatehouse")
public ModelAndView updatehouse(House house) {
int i=houseDao.updatehouse(house);
ModelAndView mv = new ModelAndView("redirect:/index.jsp");
return mv;
} }

前台:

 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript"
src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
<link rel="shortcut icon" href="img/logo1.jpg"/>
<link type="text/css" rel="stylesheet"
href="jquery-easyui-1.5.1/themes/icon.css"></link>
<link type="text/css" rel="stylesheet"
href="jquery-easyui-1.5.1/themes/default/easyui.css"></link>
<script type="text/javascript"
src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
<title>租房管理</title>
<%
String basePath = request.getContextPath();
%>
<!-- <script type="text/javascript" src="js/index.js"></script> -->
<style type="text/css">
.datagrid-btable tr {
height: 30px;
}
</style>
</head> <body class="easyui-layout">
<!-- 添加商品 -->
<div data-options="region:'north',split:true"
style="height: 50px; background-color: cornflowerblue"> </div>
<!-- 对话框开始 -->
<div data-options="region:'center',split:true"
style="padding: 5px; background: #eee">
<div id="tabs" class="easyui-tabs" style="width: 100%; height: 100%;">
<div title="主页" style="">
<table id="table"></table>
<!-- 添加的表单 -->
<div id="zhong" style="display: none">
<form id="addhouse" method="post"
style="width: 600px; padding: 20px">
关键字:<input type="text" name="keyword"><br>
地区:<input type="text" name="area"><br>
面积:<input type="text" name="squaremeter"><br>
租金:<input type="text" name="rent"><br>
租赁方式:<input type="text" name="renttype"><br>
房屋类型:<input type="text" name="housetype"><br>
<input type="submit" name="" id="" value="提交" /><br>
<input type="reset" value="重置"><br>
</form>
</div>
<!-- 修改的表单 -->
<div id="gai" style="display: none">
<form id="gaihouse" action="house/updatehouse.do" method="post"
style="width: 600px; padding: 20px">
id:<input type="text" name="id"><br>
关键字:<input type="text" name="keyword"><br>
地区:<input type="text" name="area"><br>
面积:<input type="text" name="squaremeter"><br>
租金:<input type="text" name="rent"><br>
租赁方式:<input type="text" name="renttype"><br>
房屋类型:<input type="text" name="housetype"><br>
<input type="submit" name="" id="" value="提交" /><br>
<input type="reset" value="重置"><br>
</form>
</div>
</div> </div>
</div>
<!-- 对话框结束 -->
<!-- 目录开始 -->
<div data-options="region:'west',split:true" width=210>
<div id="aa" class="easyui-accordion"
style="width: 200px; height: 543px"> <div title="用户管理" style="overflow: auto; padding: 10px" >
<ul>
<li class="lis"><a id="addhouse" class="easyui-linkbutton ab"
plain="true" >添加房屋信息(先用右边按钮)</a></li>
<li class="lis"><a href="<%=basePath %>/houselook.jsp" class="easyui-linkbutton ab"
plain="true">查看租房信息2</a></li>
<li class="lis"><a href="<%=basePath %>/house/selectAll2.do" class="easyui-linkbutton ab"
plain="true">查看租房信息3</a></li>
<li class="lis"><a href="houselook3.jsp" class="easyui-linkbutton ab"
plain="true">前往租房页面</a></li>
<li class="lis"><a href="#" class="easyui-linkbutton ab"
plain="true">修改用户</a></li>
</ul>
</div>
</div>
</div>
<!-- 底部声明 -->
<div data-options="region:'south',split:true"
style="height: 40px; line-height: 40px; vertical-align: center; text-align: center;">
玛雅网络版权声明</div>
<!-- 目录结束 -->
</body>
</html>
<script type="text/javascript"> $(function() {
$('#addhouse').form({
url:'house/addhouse.do',
onSubmit: function(){
return $('#addhouse').form('validate');//如果有为空则返回false阻止提交
},
success:function(data){
if(data=="true"){
alert("添加成功");
}else if(data=="false"){
alert("请检查信息正确!");
}
}
}); $('#table').datagrid({
url : 'house/selectAll.do',
striped:true,//显示斑马线
autoRowHeight:false,//定义设置行的高度,根据该行的内容。设置为false可以提高负载性能。这里不设置,css中设置的行高无效
singleSelect:true,//只允许选择一行
pagination : true,
pageNumber : 1,
pageSize : 1,
pageList : [ 1, 3, 5 ], toolbar : [{
iconCls : 'icon-edit',
text : "添加",
handler : function() {
var a = $(this).text(); $('#zhong').dialog({
width : 800,
height : 500,
title : a,
//closed : false,
cache : false,
modal : true
}); }
}, '-',{
iconCls : 'icon-edit',
text : "修改",
handler : function() {
var a = $(this).text();
$('#gai').dialog({
width : 800,
height : 500,
title : a,
//closed : false,
cache : false,
modal : true
});
$('#gai').dialog("open");
var r = $("#table").datagrid("getSelected");//获取被选中的行,返回对象
$("#gaihouse").form("load", r);//将被选中的信息放到弹出的的表单中,富文本编辑器的内容无法显示
}
}, '-',
{
iconCls : 'icon-cancel',
text : "删除",
handler : function() {
var id=-1;
id = $('#table').datagrid("getSelected").id;
if(id>-1){
var r1 = confirm("确定删除编号为 "+id+" 的房屋信息吗?");
if(r1) {
window.location.href="house/delhouse.do?id="+id;
alert("删除成功");
}
}else{
alert("请选中需要删除的商品");
} }
} ], frozenColumns : [ [ {
field : '',
title : '',
width : 20,
checkbox : true
} ] ],
columns : [ [ {
field : "id",
title : "信息编号",
width:65
},{
field : "keyword",
title : "关键字",
width:180
},
{
field : "area",
title : "地区",
width:60
}, {
field : "squaremeter",
title : "面积",
width:60
}, {
field : "rent",
title : "租金",
width:40
} , {
field : "renttype",
title : "租赁方式",
width:60
} ,{
field : "housetype",
title : "房屋类型",
width : 60
} ] ], });
});
</script>
  <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.List,com.hanqi.model.House,com.hanqi.controller.HouseController"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript"
src="jquery-easyui-1.5.1/jquery.easyui.min.js"></script>
<link rel="shortcut icon" href="img/logo1.jpg"/>
<link type="text/css" rel="stylesheet"
href="jquery-easyui-1.5.1/themes/icon.css"></link>
<link type="text/css" rel="stylesheet"
href="jquery-easyui-1.5.1/themes/default/easyui.css"></link>
<script type="text/javascript"
src="jquery-easyui-1.5.1/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
<form action="house/selectinfo.do" method="post">
区域:<input type="radio" name="area" id="s1" value="张店"/>
    <label for="s1">张店</label>
  <input type="radio" name="area" id="s2" value="淄川"/>
    <label for="s2">淄川</label>
  <input type="radio" name="area" id="s0" value="周村"/>
    <label for="s0">周村</label><br>
租赁类型:<input type="checkbox" name="renttype" id="s3" value="整租"/>
    <label for="s3">整租</label>
  <input type="checkbox" name="renttype" id="s4" value="合租"/>
    <label for="s4">合租</label>
  <input type="checkbox" name="renttype" id="s5" value="其他"/>
    <label for="s5">其他</label><br>
房屋类型:<input type="radio" name="housetype" id="s6" value="三室一厅"/>
    <label for="s6">三室一厅</label>
  <input type="radio" name="housetype" id="s7" value="自建房"/>
    <label for="s7">自建房</label>
  <input type="radio" name="housetype" id="s8" value="其他"/>
    <label for="s8">其他</label><br>
关键字:<input type="text" name="keyword">
<input type="submit" value="查询">
</form> <%
//HouseController hc=new HouseController();
List<House> list=(List<House>)request.getAttribute("list");
if(list!=null){
out.print("<table border='1'>");
for(House h:list){
out.print("<tr>");
out.print("<td>"+h.getKeyword()+"</td>");
out.print("<td>"+h.getArea()+"</td>");
out.print("<td>"+h.getSquaremeter()+"</td>");
out.print("<td>"+h.getRent()+"</td>");
out.print("<td>"+h.getRenttype()+"</td>");
out.print("<td>"+h.getHousetype()+"</td>");
out.print("</tr>");
}
out.print("</table>");
}
%>
</body>
</html>

SSM框架整合项目 :租房管理系统

上一篇:matlab实现高斯消去法、LU分解


下一篇:JAVAEE——宜立方商城01:电商行业的背景、商城系统架构、后台工程搭建、SSM框架整合