1、 房源管理功能修改

master
pan 5 years ago
parent ff1028e32d
commit a6a3d670c2
  1. 1
      .gitignore
  2. 20
      WebRoot/admin/communitylist.jsp
  3. 105
      WebRoot/admin/houseadd.jsp
  4. 211
      WebRoot/admin/houseedit.jsp
  5. 50
      WebRoot/admin/houselist.jsp
  6. 1
      src/beans.xml
  7. 8
      src/com/app/action/AppAction.java
  8. 4
      src/com/app/action/ApplyAction.java
  9. 19
      src/com/app/action/CommunityAction.java
  10. 139
      src/com/app/action/HouseAction.java
  11. 34
      src/com/app/bean/Community.java
  12. 31
      src/com/app/bean/House.hbm.xml
  13. 481
      src/com/app/bean/House.java
  14. 42
      src/com/app/service/CommunityServiceImpl.java
  15. 2
      src/com/app/servlet/RegionServlet.java
  16. 21
      src/log4j-config.properties
  17. 15
      src/struts.xml

1
.gitignore vendored

@ -100,3 +100,4 @@ hs_err_pid*
/WebRoot/uploadFile/
/WebRoot/WEB-INF/classes/
*.iml
/WebRoot/logs/

@ -35,7 +35,7 @@
{
//sel=="city"?$("#area").html(""):false
$("#"+sel).html("");
$.get("<%=basePath%>rg.sl?id="+parentId,function(e){
$.get("<%=basePath%>rg.sl?flag=1&id="+parentId,function(e){
$("#"+sel).html(e);
sel==="city"?reload():false;
})
@ -64,11 +64,11 @@
<div class="input-group-prepend">
<label class="input-group-text">省:</label>
</div>
<select id="province" class="custom-select" name="community.pid"></select>
<select id="province" class="custom-select" name="community.pid" onchange="loadRegion('city',province.value)"></select>
<div class="input-group-prepend">
<label class="input-group-text">市:</label>
</div>
<select id="city" class="custom-select" name="community.cid"></select>
<select id="city" class="custom-select" name="community.cid" onchange="loadRegion('area',city.value)"></select>
<div class="input-group-prepend">
<label class="input-group-text">区:</label>
</div>
@ -103,16 +103,16 @@
<tbody>
<c:forEach items="${list}" var="item">
<tr class="even gradeA">
<td>${item.name}</td>
<td class="align-middle"><a href="/admin/house/list.do?communityId=${item.id}">${item.name}</a></td>
<td>
<img style="width: 100px;height: 100px" src="<%=basePath%>${item.image}"/>
</td>
<td>${item.pid}-${item.cid}-${item.aid}</td>
<td>${item.userId}</td>
<td>${item.address}</td>
<td>${item.houseType}</td>
<td>0/0</td>
<td>
<td class="align-middle">${item.pid}-${item.cid}-${item.aid}</td>
<td class="align-middle">${item.userId}</td>
<td class="align-middle">${item.address}</td>
<td class="align-middle">${item.houseType}</td>
<td class="align-middle">${item.remain}/${item.total}</td>
<td class="align-middle">
<a href="<%=basePath%>admin/community/toUpdate.do?community.id=${item.id}&type=${param.type}">
<i class="icon-pencil"></i>
编辑

@ -39,34 +39,35 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<div class="block">
<form method="POST" action="<%=basePath%>admin/house/addhouse.do" enctype="multipart/form-data">
<input name="communityId" type="hidden" value="${param.communityId}"/>
<table class="form">
<tbody>
<tr>
<td class="col1">
<label>
房源名称</label>
户型</label>
</td>
<td class="col3">
<input name="rooname" required value="" type="text" class="medium" id="grumble">
<input name="cate" required value="" type="text" class="medium" >
</td>
</tr>
<tr>
<td class="col1">
<label>
房源大小</label>
面积</label>
</td>
@ -83,7 +84,7 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<label>
</label>
价</label>
</td>
@ -93,61 +94,10 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
</td>
</tr>
<tr>
<td class="col1">
<label>
详细地址</label>
</td>
<td class="col3">
<input name="address" required value="" type="text" class="medium" id="grumble">
</td>
</tr>
<tr>
<td class="col1">
<label>
地址经纬度</label>
</td>
<td class="col3">
<input style="display:inline-block;width:45%;" name="lat" required value="" type="text" class="medium" id="lat">
<input style="display:inline-block;width:45%;" name="lng" required value="" type="text" class="medium" id="lng">
<div style="position:absolute;right:0px;top:0px; width:44%;height:450px;" id="allmap"></div>
</td>
</tr>
<input name="num" value="1" type="hidden"/>
<tr>
<td class="col1">
<label>
房源类型</label>
</td>
<td class="col3">
<input name="cate" required value="" type="text" class="medium" id="grumble">
</td>
</tr>
<tr>
@ -167,50 +117,42 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
</td>
</tr>
<tr>
<td>
<tr>
<td class="col1">
<label>
简介</label>
总量</label>
</td>
<td>
<textarea name="description" required style="width:550px;height:80px;">
</textarea>
<td class="col3">
<input name="total" required value="" type="number" class="medium" >
</td>
</tr>
<tr>
<td>
<td class="col1">
<label>
详细描述</label>
余量</label>
</td>
<td>
<textarea name="content" required style="width:550px;height:80px;">
</textarea>
<td class="col3">
<input name="remain" required value="" type="number" class="medium" >
</td>
</tr>
<tr>
<td></td>
<td colspan="">
@ -296,17 +238,6 @@ $().ready(function(){
</script>
<script>
</script>
<link href="<%=basePath %>static/toastr-master/toastr.min.css" rel="stylesheet" type="text/css" />
<script src="<%=basePath %>static/toastr-master/toastr.min.js"></script>
<script>
<c:if test="${!empty state }">
toastr.${state}('${message}', '提示');
setTimeout(function(){
window.location.href = "<%=basePath%>${url}";
},1500)
</c:if>
</script>
</html>

@ -38,219 +38,124 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<div class="block">
<form method="POST" action="<%=basePath%>admin/house/updatehouse.do" enctype="multipart/form-data">
<input name="communityId" type="hidden" value="${param.communityId}"/>
<input name="id" type="hidden" value="${param.id}">
<table class="form">
<tbody>
<tr>
<td class="col1">
<label>
房源名称</label>
<tr>
</td>
<td class="col3">
<input name="id" value="${model.id}" type="hidden"/>
<input name="num" value="1" type="hidden"/>
<input name="rooname" required value="${model.rooname}" type="text" class="medium" id="grumble">
</td>
<td class="col1">
</tr>
<tr>
<label>
<td class="col1">
户型</label>
<label>
</td>
房源大小</label>
<td class="col3">
</td>
<input name="cate" required value="${model.cate}" type="text" class="medium" >
</td>
<td class="col3">
</tr>
<input name="size" required value="${model.size}" type="text" class="medium" id="grumble">
</td>
<tr>
</tr>
<!-- 添加状态 strat -->
<tr>
<td class="col1">
<td class="col1">
<label>
<label>
面积</label>
状态</label>
</td>
</td>
<td class="col3">
<td class="col3">
<select name="state" class="form-control">
<c:if test="${model.state==1 }">
<option value="1" selected="selected">闲置</option>
<option value="2">使用中</option>
</c:if>
<c:if test="${model.state==2 }">
<option value="1">闲置</option>
<option value="2" selected="selected">使用中</option>
</c:if>
</select>
</td>
<input name="size" required value="${model.size}" type="text" class="medium" id="grumble">
</td>
</tr>
<!-- 添加状态 end -->
<tr>
</tr>
<td class="col1">
<tr>
<label>
<td class="col1">
价格</label>
<label>
</td>
单价</label>
<td class="col3">
</td>
<input name="price" required value="${model.price}" type="text" class="medium" id="grumble">
</td>
<td class="col3">
</tr>
<tr>
<input name="price" required value="${model.price}" type="text" class="medium" id="grumble">
</td>
<td class="col1">
</tr>
<label>
详细地址</label>
<input name="num" value="1" type="hidden"/>
</td>
<td class="col3">
<tr>
<input name="address" required value="${model.address}" type="text" class="medium" id="grumble">
</td>
<td class="col1">
</tr>
<tr>
<label>
<td class="col1">
图片</label>
<label>
</td>
地址经纬度</label>
<td class="col2">
</td>
<input name="thunb" required value="${model.thunb}" type="text" id="attachfile">
<a href="javascript:;" class="uploadImg btn btn-default">点击上传</a>
</td>
</td>
<td class="col3">
</tr>
<input style="display:inline-block;width:45%;" name="lat" required value="${model.lat}" type="text" class="medium" id="lat">
<input style="display:inline-block;width:45%;" name="lng" required value="${model.lng}" type="text" class="medium" id="lng">
<div style="position:absolute;right:0px;top:0px; width:44%;width:800px;height:450px;" id="allmap"></div>
</td>
<tr>
</tr>
<tr>
<td class="col1">
<td class="col1">
<label>
<label>
总量</label>
房源类型</label>
</td>
</td>
<td class="col3">
<td class="col3">
<input name="total" required value="${model.total}" type="number" class="medium" >
</td>
<input name="cate" required value="${model.cate}" type="text" class="medium" id="grumble">
</td>
</tr>
</tr>
<tr>
<tr>
<td class="col1">
<label>
图片</label>
</td>
<td class="col2">
<a href="<%=basePath%>${model.thunb}" target="_blank">
查看
</a>
<br/>
<input name="thunb" required value="${model.thunb}" type="text" id="attachfile">
<a href="javascript:;" class="uploadImg btn btn-default">点击上传</a>
</td>
</td>
</tr>
<tr>
<td>
<label>
简介</label>
余量</label>
</td>
<td>
<textarea name="description" required style="width:550px;height:80px;">
${model.description}</textarea>
<td class="col3">
<input name="remain" required value="${model.remain}" type="number" class="medium" >
</td>
</tr>
<tr>
<td>
<label>
详细描述</label>
</td>
<td>
<textarea name="content" required style="width:550px;height:80px;">
${model.content}</textarea>
</td>
</tr>
<tr>
<td></td>
<td colspan="">
<button type="submit" class="btn btn-blue">提交数据</button>
</td>
<td></td>
<td colspan="">
<button type="submit" class="btn btn-blue">提交数据</button>
</td>
</tr>
</tbody></table>

@ -34,9 +34,10 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<form class="form-inline" role="form"
action="<%=basePath%>admin/house/list.do" method="post"
autocomplete="off">
<input type="hidden" name="communityId" value="${param.communityId}"/>
<div class="form-group" style="margin-right: 10px">
<label for="housename">房源名称:</label> <input class="form-control"
name="housename" type="text" placeholder="根据房源名称搜索">
<label >户型:</label> <input class="form-control"
name="cate" type="text" placeholder="根据户型搜索">
</div>
<div class="form-group" style="margin-right: 10px">
<button type="submit" class="btn btn-primary">查询</button>
@ -52,20 +53,18 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<div>
<a class="btn btn-primary" href="<%=basePath%>admin/house/add.do">新增房源</a>
<a class="btn btn-primary" href="<%=basePath%>admin/house/add.do?communityId=${param.communityId}">新增房源</a>
</div>
<table id="example" class="data display datatable">
<thead>
<tr>
<th>房源名称</th>
<th>发布人</th>
<th>大小</th>
<th>位置</th> <th>价格</th>
<th>房源类型</th>
<th>状态</th>
<th>户型</th>
<th>面积</th>
<th>单价</th>
<th>图片</th>
<th>余量/总量</th>
<th style="width: 150px;">操作</th>
</tr>
</thead>
@ -74,31 +73,25 @@ String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.
<c:forEach items="${list}" var="item">
<tr class="even gradeA">
<td>
${item.rooname}</td> <td>${item.username}</td>
<td>${item.size}</td>
<td>${item.address}</td>
<td>${item.price}</td>
<td class="align-middle">${item.cate}</td>
<td class="align-middle">${item.size}</td>
<td class="align-middle">${item.price}</td>
<td class="align-middle"><img style="width: 100px;height: 100px" src="<%=basePath%>${item.thunb}"/></td>
<td>${item.cate}</td>
<td>
<c:if test="${item.state==1 }">闲置</c:if>
<c:if test="${item.state==2 }">使用中</c:if>
</td>
<td>
<td class="align-middle">${item.remain}/${item.total}</td>
<td class="align-middle">
<a href="<%=basePath%>admin/house/edit.do?id=${item.id}">
<a href="<%=basePath%>admin/house/edit.do?id=${item.id}&communityId=${param.communityId}">
<i class="icon-pencil"></i>
编辑
</a>
<a class="deletemodal" href="<%=basePath%>admin/house/delete.do?ret=list&id=${item.id}"><i class="icon-remove"></i>
<a class="deletemodal" href="<%=basePath%>admin/house/delete.do?id=${item.id}&communityId=${param.communityId}"><i class="icon-remove"></i>
移除
</a>
</td>
@ -145,8 +138,6 @@ $(document).ready(function(){
loadRegion(sel,$(this).val());
});
})
function loadRegion(sel,parentId)
@ -169,11 +160,8 @@ $(document).ready(function(){
<link href="<%=basePath %>static/toastr-master/toastr.min.css" rel="stylesheet" type="text/css" />
<script src="<%=basePath %>static/toastr-master/toastr.min.js"></script>
<script>
<c:if test="${!empty state }">
toastr.${state}('${message}', '提示');
setTimeout(function(){
window.location.href = "<%=basePath%>${url}";
},1500)
<c:if test="${!empty stateType }">
toastr.${stateType}('${message}', '提示');
</c:if>
</script>

@ -38,7 +38,6 @@
<value>com/app/bean/Ads.hbm.xml</value>
<value>com/app/bean/Apply.hbm.xml</value>
<value>com/app/bean/Cates.hbm.xml</value>
<value>com/app/bean/House.hbm.xml</value>
<value>com/app/bean/News.hbm.xml</value>
<value>com/app/bean/Region.hbm.xml</value>
<value>com/app/bean/Report.hbm.xml</value>

@ -86,11 +86,11 @@ public class AppAction {
Iterator<House> iterator = houses.iterator();
while(iterator.hasNext()) {
House next = iterator.next();
String userid = next.getUserid();
if (userid==null||userid.trim().equals("")) {
Integer userid = next.getUserid();
if (userid==null) {
iterator.remove();
}else {
Users users = usersService.findById(Integer.parseInt(userid));
Users users = usersService.findById(userid);
if (users==null||(!areaid.equals(users.getAid()))) {
iterator.remove();
}
@ -181,7 +181,7 @@ public class AppAction {
model.setMessage(messagex);
applyService.save(model);
model1.setState("2");
model1.setState(2);
houseService.update(model1);
act.put("message", "申请提交成功");
act.put("state", "success");

@ -198,9 +198,9 @@ public class ApplyAction {
Apply model = applyService.findById(id);
House hs = houseService.findById(model.getHid());
if (statex.equals("6"))
hs.setState("1");
hs.setState(1);
if (statex.equals("5"))
hs.setState("2");
hs.setState(2);
houseService.update(hs);
model.setState(statex);
applyService.update(model);

@ -78,11 +78,23 @@ public class CommunityAction {
*/
public String list() throws UnsupportedEncodingException {
ActionContext act = ActionContext.getContext();
act.put(Constants.LIST,communityService.list(community,type.getType()));
HttpServletRequest request=ServletActionContext.getRequest();
if(!request.getParameterMap().containsKey("community.name")){
community.setName(null);
}
if(!request.getParameterMap().containsKey("community.pid")){
community.setPid(null);
}
if(!request.getParameterMap().containsKey("community.cid")){
community.setCid(null);
}
if(!request.getParameterMap().containsKey("community.aid")){
community.setAid(null);
}
act.put(Constants.LIST,communityService.list(community,type.getType()));
this.setState(request.getParameter("state")==null?null:StateType.valueOf(request.getParameter("state")));
this.setMessage(request.getParameter("message"));
this.setState(request.getParameter(Constants.STATE)==null?null:StateType.valueOf(request.getParameter(Constants.STATE)));
this.setMessage(request.getParameter(Constants.MESSAGE));
return Constants.SUCCESS;
}
@ -122,7 +134,6 @@ public class CommunityAction {
}
public String update() throws IOException {
ActionContext act = ActionContext.getContext();
Community update=communityService.findById(community.getId());
update.setName(community.getName());
update.setImage(community.getImage());

@ -1,12 +1,17 @@
package com.app.action;
import com.app.bean.Community;
import com.app.bean.House;
import com.app.bean.Users;
import com.app.service.CommunityService;
import com.app.service.HouseService;
import com.app.service.UsersService;
import com.app.utils.Constants;
import com.app.utils.MainUtils;
import com.app.utils.StateType;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
@ -23,13 +28,13 @@ public class HouseAction {
@Resource
UsersService usersService;
public int id;
public Integer id;
public void setId(int id) {
public void setId(Integer id) {
this.id = id;
}
public int getId() {
public Integer getId() {
return id;
@ -185,6 +190,56 @@ public class HouseAction {
return state;
}
private Integer communityId;
private Integer total;
private Integer remain;
public Integer getCommunityId() {
return communityId;
}
public void setCommunityId(Integer communityId) {
this.communityId = communityId;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getRemain() {
return remain;
}
public void setRemain(Integer remain) {
this.remain = remain;
}
private StateType stateType;
private String message;
public StateType getStateType() {
return stateType;
}
public void setStateType(StateType stateType) {
this.stateType = stateType;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String add() {
return "success";
}
@ -198,6 +253,10 @@ public String cate;
public void setCate(String cate) {
this.cate = cate;
}
@Autowired
private CommunityService communityService;
public String addHouse() {
ActionContext act = ActionContext.getContext();
Users u = (Users) act.getSession().get("users");
@ -205,24 +264,29 @@ public String cate;
model.setRooname(rooname);
model.setSize(size);
model.setThunb(thunb);
model.setPrice(price);
model.setPrice(0);
model.setCate(cate);
model.setDescription(description);
model.setCreated(MainUtils.getTime());
model.setContent(content);
model.setLat(lat);
model.setLng(lng);
model.setUserid(u.getId()+"");
model.setUserid(u.getId());
model.setUsername(u.getUsername());
model.setPid(u.getPid()+"");
model.setCid(u.getCid()+"");
model.setAid(u.getAid()+"");
model.setState("1");
Community community= communityService.findById(communityId);
model.setPid(community.getPid());
model.setCid(community.getCid());
model.setAid(community.getAid());
model.setState(1);
model.setAddress(address);
model.setCommunityId(communityId);
model.setTotal(total);
model.setRemain(remain);
houseService.save(model);
act.put("message", "上传房源成功!");
act.put("state", "success");
act.put("url", "admin/house/list.do");
this.setMessage("上传房源成功!");
this.setStateType(StateType.success);
this.setCommunityId(communityId);
return "success";
}
@ -234,37 +298,36 @@ public String cate;
}
public String updateHouse() {
ActionContext act = ActionContext.getContext();
House model = houseService.findById(id);
model.setRooname(rooname);
model.setCate(cate);
model.setSize(size);
model.setAddress(address);
model.setThunb(thunb);model.setCate(cate);
model.setPrice(price);
model.setDescription(description);
model.setContent(content);
model.setLat(lat);
model.setState(state);
model.setLng(lng);
model.setPrice(0);
model.setThunb(thunb);
model.setTotal(total);
model.setRemain(remain);
houseService.update(model);
act.put("message", "更新房源成功!");
act.put("url", "admin/house/edit.do?id=" + id);
act.put("state", "success");
this.setMessage("更新房源成功!");
this.setStateType(StateType.success);
this.setCommunityId(communityId);
return "success";
}
public String houseList() {
HttpServletRequest request = ServletActionContext.getRequest();
String housename = request.getParameter("housename");
ActionContext act = ActionContext.getContext();
//根据条件查询
if (housename==null||"".equals(housename.trim())) {
List<House> list = houseService.list();
act.put("list", list);
}else {
List<House> list = houseService.list("from House where rooname like '%"+housename+"%' ");
act.put("list", list);
String query="";
if(request.getParameterMap().containsKey("cate")){
query=" and cate like '%"+this.cate+"%'";
}
//根据条件查询
List<House> list = houseService.list("from House where community_id="+this.communityId+query);
act.put("list", list);
this.setStateType(request.getParameter(Constants.STATE)==null?null:StateType.valueOf(request.getParameter(Constants.STATE)));
this.setMessage(request.getParameter(Constants.MESSAGE));
return "success";
}
@ -286,12 +349,10 @@ public String cate;
}
public String delete() {
Integer id = this.id;
houseService.delete(id);
ActionContext act = ActionContext.getContext();
act.put("message", "删除房源成功!");
act.put("state", "success");
act.put("url", "admin/house/"+ret+".do");
houseService.delete(this.id);
this.setMessage("删除房源成功!");
this.setStateType(StateType.success);
this.setCommunityId(communityId);
return "success";
}

@ -1,6 +1,7 @@
package com.app.bean;
import javax.persistence.*;
import java.util.List;
@Entity
public class Community {
@ -18,6 +19,11 @@ public class Community {
private Integer userId;
private Integer type;
private Integer total;
private Integer remain;
private List<House> houseList;
@Id
@Column(name = "id")
@SequenceGenerator(name="increment")
@ -149,4 +155,32 @@ public class Community {
public void setType(Integer type) {
this.type = type;
}
@Transient
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
@Transient
public Integer getRemain() {
return remain;
}
public void setRemain(Integer remain) {
this.remain = remain;
}
@OneToMany(cascade=CascadeType.ALL,targetEntity = House.class)
@JoinColumn(name="community_id",referencedColumnName = "id")
public List<House> getHouseList() {
return houseList;
}
public void setHouseList(List<House> houseList) {
this.houseList = houseList;
}
}

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.app.bean">
<class name="House">
<id name="id" column="ID" type="int">
<generator class="identity" />
</id><property name="rooname" not-null="false" type="java.lang.String" />
<property name="size" not-null="false" type="java.lang.String" />
<property name="thunb" not-null="false" type="java.lang.String" />
<property name="price" not-null="false" type="java.lang.String" />
<property name="description" not-null="false" type="java.lang.String" />
<property name="created" not-null="false" type="java.lang.String" />
<property name="content" not-null="false" type="java.lang.String" />
<property name="lat" not-null="false" type="java.lang.String" />
<property name="lng" not-null="false" type="java.lang.String" />
<property name="userid" not-null="false" type="java.lang.String" />
<property name="username" not-null="false" type="java.lang.String" />
<property name="pid" not-null="false" type="java.lang.String" />
<property name="cid" not-null="false" type="java.lang.String" />
<property name="aid" not-null="false" type="java.lang.String" />
<property name="state" not-null="false" type="java.lang.String" />
<property name="address" not-null="false" type="java.lang.String" />
<property name="cate" not-null="false" type="java.lang.String" />
<property name="communityId" not-null="true" type="java.lang.Integer"/>
<property name="total" not-null="true" type="java.lang.Integer"/>
<property name="remain" not-null="true" type="java.lang.Integer"/>
</class></hibernate-mapping>

@ -1,213 +1,274 @@
package com.app.bean;
public class House {
public int id;
public String rooname;
public String address;
public String cate;
private Integer communityId;
private Integer total;
private Integer remain;
public Integer getCommunityId() {
return communityId;
}
public void setCommunityId(Integer communityId) {
this.communityId = communityId;
}
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
public Integer getRemain() {
return remain;
}
public void setRemain(Integer remain) {
this.remain = remain;
}
public String getCate() {
return cate;
}
public void setCate(String cate) {
this.cate = cate;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public void setRooname(String rooname) {
this.rooname = rooname;
}
public String getRooname() {
return rooname;
}
public String size;
public void setSize(String size) {
this.size = size;
}
public String getSize() {
return size;
}
public String thunb;
public void setThunb(String thunb) {
this.thunb = thunb;
}
public String getThunb() {
return thunb;
}
public String price;
public void setPrice(String price) {
this.price = price;
}
public String getPrice() {
return price;
}
public String description;
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
public String created;
public void setCreated(String created) {
this.created = created;
}
public String getCreated() {
return created;
}
public String content;
import javax.persistence.*;
import java.util.Objects;
public void setContent(String content) {
this.content = content;
}
public String getContent() {
return content;
}
public String lat;
public void setLat(String lat) {
this.lat = lat;
}
public String getLat() {
return lat;
}
public String lng;
public void setLng(String lng) {
this.lng = lng;
}
public String getLng() {
return lng;
}
public String userid;
public void setUserid(String userid) {
this.userid = userid;
}
public String getUserid() {
return userid;
}
public String username;
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public String pid;
public void setPid(String pid) {
this.pid = pid;
}
public String getPid() {
return pid;
}
public String cid;
public void setCid(String cid) {
this.cid = cid;
}
public String getCid() {
return cid;
}
public String aid;
public void setAid(String aid) {
this.aid = aid;
}
public String getAid() {
return aid;
}
public String state;
public void setState(String state) {
this.state = state;
}
public String getState() {
return state;
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
}
@Entity
public class House {
private Integer id;
private String rooname;
private String size;
private String thunb;
private Integer price;
private String description;
private String created;
private String content;
private String lat;
private String lng;
private Integer userid;
private String username;
private Integer pid;
private Integer cid;
private Integer aid;
private Integer state;
private String address;
private String cate;
private Integer communityId;
private Integer total;
private Integer remain;
@Id
@Column(name = "id")
@SequenceGenerator(name="increment")
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Basic
@Column(name = "rooname")
public String getRooname() {
return rooname;
}
public void setRooname(String rooname) {
this.rooname = rooname;
}
@Basic
@Column(name = "size")
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
@Basic
@Column(name = "thunb")
public String getThunb() {
return thunb;
}
public void setThunb(String thunb) {
this.thunb = thunb;
}
@Basic
@Column(name = "price")
public Integer getPrice() {
return price;
}
public void setPrice(Integer price) {
this.price = price;
}
@Basic
@Column(name = "description")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Basic
@Column(name = "created")
public String getCreated() {
return created;
}
public void setCreated(String created) {
this.created = created;
}
@Basic
@Column(name = "content")
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Basic
@Column(name = "lat")
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
@Basic
@Column(name = "lng")
public String getLng() {
return lng;
}
public void setLng(String lng) {
this.lng = lng;
}
@Basic
@Column(name = "userid")
public Integer getUserid() {
return userid;
}
public void setUserid(Integer userid) {
this.userid = userid;
}
@Basic
@Column(name = "username")
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Basic
@Column(name = "pid")
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
@Basic
@Column(name = "cid")
public Integer getCid() {
return cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
@Basic
@Column(name = "aid")
public Integer getAid() {
return aid;
}
public void setAid(Integer aid) {
this.aid = aid;
}
@Basic
@Column(name = "state")
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}
@Basic
@Column(name = "address")
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Basic
@Column(name = "cate")
public String getCate() {
return cate;
}
public void setCate(String cate) {
this.cate = cate;
}
@Basic
@Column(name = "community_id")
public Integer getCommunityId() {
return communityId;
}
public void setCommunityId(Integer communityId) {
this.communityId = communityId;
}
@Basic
@Column(name = "total")
public Integer getTotal() {
return total;
}
public void setTotal(Integer total) {
this.total = total;
}
@Basic
@Column(name = "remain")
public Integer getRemain() {
return remain;
}
public void setRemain(Integer remain) {
this.remain = remain;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
House house = (House) o;
return Objects.equals(id, house.id) &&
Objects.equals(rooname, house.rooname) &&
Objects.equals(size, house.size) &&
Objects.equals(thunb, house.thunb) &&
Objects.equals(price, house.price) &&
Objects.equals(description, house.description) &&
Objects.equals(created, house.created) &&
Objects.equals(content, house.content) &&
Objects.equals(lat, house.lat) &&
Objects.equals(lng, house.lng) &&
Objects.equals(userid, house.userid) &&
Objects.equals(username, house.username) &&
Objects.equals(pid, house.pid) &&
Objects.equals(cid, house.cid) &&
Objects.equals(aid, house.aid) &&
Objects.equals(state, house.state) &&
Objects.equals(address, house.address) &&
Objects.equals(cate, house.cate) &&
Objects.equals(communityId, house.communityId) &&
Objects.equals(total, house.total) &&
Objects.equals(remain, house.remain);
}
@Override
public int hashCode() {
return Objects.hash(id, rooname, size, thunb, price, description, created, content, lat, lng, userid, username, pid, cid, aid, state, address, cate, communityId, total, remain);
}
}

@ -5,6 +5,7 @@ import org.apache.log4j.Logger;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.HibernateTemplate;
@ -69,7 +70,7 @@ public class CommunityServiceImpl implements CommunityService{
@Override
public List<Community> list(Community community,Integer type) {
DetachedCriteria criteria= DetachedCriteria.forClass(Community.class,"c");
DetachedCriteria criteria= DetachedCriteria.forClass(Community.class);
criteria.add(Restrictions.eq("type",type));
if(community!=null) {
if (community.getName() != null && community.getName().length() > 0) {
@ -85,12 +86,41 @@ public class CommunityServiceImpl implements CommunityService{
criteria.add(Restrictions.eq("aid", community.getAid()));
}
}
// DetachedCriteria house = DetachedCriteria.forClass(House.class,"h");
// house.add(Restrictions.eq("h.communityId","c.id"));
// criteria.add(Subqueries.exists(house.setProjection(Projections.rowCount())));
String sql= "select community.id,\n" +
" community.name,\n" +
" community.image,\n" +
" community.pid,\n" +
" community.cid,\n" +
" community.aid,\n" +
" community.address,\n" +
" community.longitude,\n" +
" community.latitude,\n" +
" community.house_type as houseType,\n" +
" community.description,\n" +
" community.type as type,\n" +
" community.user_id as userId,\n" +
" b.total,\n" +
" b.remain\n" +
"from community,\n" +
" (select community.id,\n" +
" sum(house.total) as total,\n" +
" sum(house.remain) as remain\n" +
" from community,\n" +
" house\n" +
" where community.id = house.community_id\n" +
" group by community.id) b\n" +
"where community.id = b.id" +
(community.getName() != null && community.getName().length() > 0?" and community.name like '%"+community.getName()+"%'":"") +
(community.getPid() != null?" and community.pid="+community.getPid():"")+
(community.getCid() != null?" and community.cid="+community.getCid():"")+
(community.getAid() != null?" and community.aid="+community.getAid():"");
List<Community> communities=hibernateTemplate.getSessionFactory().getCurrentSession().createSQLQuery(sql).setResultTransformer(Transformers.aliasToBean(Community.class)).list();
try {
return hibernateTemplate.findByCriteria(criteria);
} catch (DataAccessException e) {
return communities;
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
return new ArrayList<>();

@ -45,7 +45,7 @@ public class RegionServlet extends HttpServlet {
String flag = request.getParameter("flag");
DB db = new DB();
db.open();
String html = "<option value='' selected='selected'>ÇëÑ¡Ôò</option>";
String html = "<option value='' selected='selected'>ÇëÑ¡Ôñ</option>";
if (!"1".equals(flag)) {
html="";
}

@ -1,5 +1,5 @@
log4j.rootLogger = debug,Console,D
log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
#控制日志的输出等级和分类
# log4j.rootLogger = [ level ] , appenderName, appenderName, …
@ -22,7 +22,24 @@ log4j.appender.Console.layout = org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern= [%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n
 
########### hibernate
log4j.logger.org.hibernate=debug
log4j.logger.org.hibernate.hql.ast.AST=DEBUG
#下面的两条配置非常重要,设置为trace后,将可以看到打印出sql中 ? 占位符的实际内容
#this is the most important config for showing parames like ?
log4j.logger.org.hibernate.SQL=trace
log4j.logger.org.hibernate.type=trace
#above two configs
log4j.logger.org.hibernate.tool.hbm2ddl=DEBUG
log4j.logger.org.hibernate.hql=DEBUG
log4j.logger.org.hibernate.cache=debug
log4j.logger.org.hibernate.transaction=DEBUG
log4j.logger.org.hibernate.jdbc=DEBUG
log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
### 输出DEBUG 级别以上的日志到服务器/logs/debug.log ###

@ -183,13 +183,19 @@
</action>
<action name="addhouse" method="addHouse" class="houseAction">
<result>/admin/houseadd.jsp</result>
<result type="redirect">
<param name="location">list.do?state=${stateType}&amp;message=${message}&amp;communityId=${communityId}</param>
<param name="encode">true</param>
</result>
</action>
<action name="edit" method="editHouse" class="houseAction">
<result>/admin/houseedit.jsp</result>
</action>
<action name="updatehouse" method="updateHouse" class="houseAction">
<result>/admin/houseedit.jsp</result>
<result type="redirect">
<param name="location">list.do?state=${stateType}&amp;message=${message}&amp;communityId=${communityId}</param>
<param name="encode">true</param>
</result>
</action>
<action name="list" method="houseList" class="houseAction">
<result>/admin/houselist.jsp</result>
@ -198,7 +204,10 @@
<result>/admin/myhouselist.jsp</result>
</action>
<action name="delete" method="delete" class="houseAction">
<result>/admin/houselist.jsp</result>
<result type="redirect">
<param name="location">list.do?state=${stateType}&amp;message=${message}&amp;communityId=${communityId}</param>
<param name="encode">true</param>
</result>
</action>
</package>

Loading…
Cancel
Save