CommunityController
package com.wise.SpringController.web.songduweb;
import com.wise.SpringController.service.CommunityService;
import com.wise.SpringController.model.T_Community;
import com.wise.SpringController.model.T_Juwei;
import com.wise.SpringController.tool.CustomResponse;
import com.wise.SpringController.tool.StringUtils;
import com.wise.SpringController.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping("/community")
public class CommunityController extends BaseController {
@Autowired
private CommunityService communityService;
@GetMapping("/index")
public String community() {
return "community/index";
}
@PostMapping("/list")
@ResponseBody
public Object list(T_Community communityBean) {
startPage();
List<Map<String,Object>> list = communityService.selectCommunityList(communityBean);
return getCustomResponse(list);
}
@RequestMapping("/formView")
public String formView(String id, Model model){
T_Community communityBean=null;
if (id != null) {
communityBean=communityService.selectCommunityById(id);
} else {
communityBean=new T_Community();
}
model.addAttribute("communityBean",communityBean);
List<Map<String,Object>> t_juwei= communityService.selectJuwei();
model.addAttribute("juweiBean",t_juwei);
return "community/form";
}
@ResponseBody
@RequestMapping("/insertCommunity")
public Object insertCommunity(T_Community communityBean,String juweiCode){
if (communityBean!=null){
Map<String,Object> juwei = communityService.selectByJuweiCode(juweiCode);
communityBean.setJuwei(juwei.get("JUWEINAMEFULL").toString());
if (StringUtils.isNotEmpty(communityBean.getId())){
communityService.updateCommunity(communityBean);
return new CustomResponse(true,"修改成功");
}else{
communityService.insertCommunity(communityBean);
return new CustomResponse(true,"保存成功");
}
}else{
return new CustomResponse(false,"保存失败");
}
}
@RequestMapping("deleteById")
@ResponseBody
public Object deleteById(String id) {
try {
communityService.deleteById(id);
return new CustomResponse(true, "删除成功");
} catch (Exception e) {
return new CustomResponse(true, "删除失败");
}
}
}
CommunityService(接口)
package com.wise.SpringController.service;
import com.wise.SpringController.model.T_Community;
import com.wise.SpringController.model.T_Juwei;
import java.util.List;
import java.util.Map;
public interface CommunityService {
int insertCommunity(T_Community t_community);
int updateCommunity(T_Community t_community);
List<Map<String,Object>> selectCommunityList(T_Community t_community);
List<Map<String,Object>> selectJuwei();
Map<String,Object> selectByJuweiCode(String juweiCode);
T_Community selectCommunityById(String id);
int deleteById(String id);
T_Community wxCommunityDetails(String id);
}
CommunityServicelmpl
package com.wise.SpringController.service.impl;
import com.wise.SpringController.dao.SdTCommunityMapper;
import com.wise.SpringController.model.T_Community;
import com.wise.SpringController.model.T_Juwei;
import com.wise.SpringController.service.CommunityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
@Service
public class CommunityServicelmpl implements CommunityService{
@Autowired
private SdTCommunityMapper tCommunityMapper;
@Override
public T_Community selectCommunityById(String id) {
return tCommunityMapper.selectCommunityById(id);
}
@Override
public List<Map<String,Object>> selectCommunityList(T_Community community) {
return tCommunityMapper.selectCommunityList(community);
}
@Override
public List<Map<String,Object>> selectJuwei() {
return tCommunityMapper.selectJuwei();
}
@Override
public Map<String,Object> selectByJuweiCode(String juweiCode) {
return tCommunityMapper.selectByJuweiCode(juweiCode);
}
@Override
public int insertCommunity(T_Community community) {
return tCommunityMapper.insertCommunity(community);
}
@Override
public int updateCommunity(T_Community community) {
return tCommunityMapper.updateCommunity(community);
}
@Override
public int deleteById(String id) {
return tCommunityMapper.deleteCommunityById(id);
}
@Override
public T_Community wxCommunityDetails(String id) {
return tCommunityMapper.wxCommunityDetails(id);
}
}
SdTCommunityMapper(接口)
package com.wise.SpringController.dao;
import com.wise.SpringController.model.T_Community;
import com.wise.SpringController.model.T_Juwei;
import java.util.List;
import java.util.Map;
public interface SdTCommunityMapper {
List<Map<String,Object>> selectCommunityList(T_Community community);
T_Community selectCommunityById(String id);
List<Map<String,Object>> selectJuwei();
Map<String,Object> selectByJuweiCode(String juweiCode);
int insertCommunity(T_Community community);
int updateCommunity(T_Community community);
int deleteCommunityById(String id);
T_Community wxCommunityDetails(String id);
List<T_Community> selectTCommunityList(T_Community t_Community);
List<Map<String,Object>> selectMapTCommunityList(T_Community t_Community);
T_Community selectTCommunityById(String id);
}
CommunityMapper.xml
<?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.wise.SpringController.dao.SdTCommunityMapper">
<resultMap type="com.wise.SpringController.model.T_Community" id="CommunityResult">
<result property="id" column="id"/>
<result property="title" column="title"/>
<result property="juweiCode" column="juwei_code"/>
<result property="communityName" column="community_name"/>
<result property="address" column="address"/>
<result property="area" column="area"/>
<result property="households" column="households"/>
<result property="juwei" column="juwei"/>
<result property="createDate" column="create_date"/>
<result property="updateDate" column="update_date"/>
</resultMap>
<sql id="selectCommunity">
SELECT tc.title,tc.id,tc.release_status,tc.juwei_code,tc.community_name,tc.address,tc.area,tc.households,tc.juwei,tc.create_date,tc.update_date
FROM T_COMMUNITY tc
</sql>
<select id="wxCommunityDetails" resultMap="CommunityResult">
SELECT tc.title,tc.id,tc.release_status,tc.juwei_code,tc.community_name,tc.address,tc.area,tc.households,tc.juwei,tc.create_date,tc.update_date
FROM T_COMMUNITY tc
where tc.id=
(select community_id from sd_wechat_user where id=#{id}) and release_status = '0'
</select>
<select id="selectCommunityList" parameterType="com.wise.SpringController.model.T_Community" resultType="map">
<include refid="selectCommunity"/>
where tc.release_status = '0'
<if test="communityName != null and communityName != ''">
AND tc.community_name like concat(concat('%',#{communityName}),'%')
</if>
</select>
<select id="selectCommunityById" parameterType="String" resultMap="CommunityResult">
SELECT tc.title,tc.id,tc.release_status,tc.juwei_code,tc.community_name,tc.address,tc.area,tc.households,tc.juwei,tc.create_date,tc.update_date
FROM T_COMMUNITY tc
where tc.id = #{id}
</select>
<insert id="insertCommunity" parameterType="com.wise.SpringController.model.T_Community" useGeneratedKeys="true" keyProperty="id">
<selectKey keyProperty="id" order="BEFORE" resultType="String">
select seq_t_community.nextval as id from DUAL
</selectKey>
insert into t_community(
<if test="id != null">id,</if>
<if test="juweiCode != null and juweiCode != ''">juwei_code,</if>
<if test="title != null and title != ''">title,</if>
<if test="communityName != null and communityName != ''">community_name,</if>
<if test="address != null and address != ''">address,</if>
<if test="area != null and area != ''">area,</if>
<if test="households != null and households != ''">households,</if>
<if test="juwei != null and juwei != ''">juwei,</if>
release_status,
create_date,
update_date
)values(
<if test="id != null ">#{id},</if>
<if test="juweiCode != null and juweiCode != ''">#{juweiCode},</if>
<if test="title != null and title != ''">#{title},</if>
<if test="communityName != null and communityName != ''">#{communityName},</if>
<if test="address != null and address != ''">#{address},</if>
<if test="area != null and area != ''">#{area},</if>
<if test="households != null and households != ''">#{households},</if>
<if test="juwei != null and juwei != ''">#{juwei},</if>
0,
sysdate,
sysdate
)
</insert>
<update id="updateCommunity" parameterType="com.wise.SpringController.model.T_Community">
update t_community
<set>
<if test="juweiCode != null and juweiCode != ''">juwei_code = #{juweiCode},</if>
<if test="title != null and title != ''">title = #{title},</if>
<if test="communityName != null and communityName != ''">community_name = #{communityName},</if>
<if test="address != null and address != ''">address = #{address},</if>
<if test="area != null and area != ''">area = #{area},</if>
<if test="households != null and households != ''">households = #{households},</if>
<if test="juwei != null and juwei != ''">juwei = #{juwei},</if>
update_date = sysdate
</set>
where id = #{id}
</update>
<delete id="deleteCommunityById">
update t_community set release_status=1 where id = #{id}
</delete>
<select id="selectJuwei" resultType="map">
select j.juweiCode,j.juweiNameFull from T_JUWEI j
</select>
<resultMap type="com.wise.SpringController.model.T_Juwei" id="JuweiResult">
<result property="id" column="id"/>
<result property="title" column="title"/>
<result property="juweiCode" column="juweiCode"/>
<result property="juweiNameFull" column="juweiNameFull"/>
</resultMap>
<select id="selectByJuweiCode" resultType="map">
select j.juweiNameFull from T_JUWEI j where j.juweiCode = #{juweiCode}
</select>
</mapper>
index.html列表页面
<!DOCTYPE html>
<html lang="zh_cn" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>小区管理</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="email=no">
<title>Title</title>
<link rel="stylesheet" th:href="@{/iframe/zui/css/zui.min.css}">
<link rel="stylesheet" th:href="@{/iframe/css/page1.css}">
<link rel="stylesheet" th:href="@{/css/zui.uploader.min.css}">
<link rel="stylesheet" th:href="@{/css/bootstrap.min.css}">
<link rel="stylesheet" th:href="@{/css/bootstrap-datetimepicker.min.css}">
<script th:src="@{/iframe/zui/lib/jquery/jquery.js}"></script>
<script type="text/javascript" th:src="@{/js/jquery-3.3.1.min.js}"></script>
<script type="text/javascript" th:src="@{/js/jquery.form.js}"></script>
<script type="text/javascript" th:src="@{/js/jquery.page.js}"></script>
<script type="text/javascript" th:src="@{/js/zui.min.js}"></script>
<script type="text/javascript" th:src="@{/js/eventcommon.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-multiselect.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-datetimepicker.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-datetimepicker.zh-CN.js}"></script>
<script type="text/javascript" th:src="@{/js/common.js}"></script>
<script type="text/javascript" th:src="@{/js/zui.uploader.min.js}"></script>
<script type="text/javascript" th:src="@{/layer/layer.js}"></script>
<script type="text/javascript" th:src="@{/js/wise.openlayer.js}"></script>
<script type="text/javascript" th:src="@{/js/laydate.js}"></script>
</head>
<body>
<div class="wrapper">
<div class="search row">
<div class="search-item col-sm-4">
<label class="search-label">小区名称</label>
<input type="text" id="communityName" name="communityName" class="form-control">
</div>
<div class="search-item col-sm-2">
<button class="btn btn-danger search-btn" type="button" onclick='loadEventList(1)'>
<i class="icon icon-search"></i>
<span class="text">搜索</span>
</button>
</div>
</div>
<div class="result">
<div class="result-option">
<a class="btn btn-danger result-btn"
th:onclick="'openlayer.openWindows(\'添加\',\''+@{/community/formView(action=add)}+'\')'" data-position="60px"
aria-hidden="true" data-backdrop="static">
<i class="icon icon-plus"></i>
<span class="text">添加小区</span>
</a>
</div>
<input type="hidden" id="dqpage">
<h2 class="result-table-title">小区列表</h2>
<div class="result-table">
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>小区名称</th>
<th>小区地址</th>
<th>面 积</th>
<th>户 数</th>
<th>所属社区</th>
<th>操 作</th>
</tr>
</thead>
<tbody class="tbody" id="tablist">
</tbody>
</table>
</div>
<!--分页-->
<div class="result-footer">
<ul class="pager" data-ride="pager"
data-elements="prev, nav, next,total_text"
data-max-nav-count="6"
data-page="1" data-rec-total="100" data-rec-per-page="10">
</ul>
</div>
</div>
</div>
</body>
<script th:inline="javascript">
var basePath =;
$(function () {
loadEventList(1);
});
function reflush() {
var pagenum = $("#dqpage").val();
loadEventList(pagenum);
}
$('.pager').pager({
page: 1,
onPageChange: function (state, oldState) {
if (typeof (oldState.page) !== "undefined") {
if (state.page !== oldState.page) {
loadEventList(state.page);
$("#dqpage").val(state.page);
}
}
}
});
function loadEventList(page) {
$.ajax({
type: "POST",
url: basePath + "community/list",
async: false,
data: "pageSize=10&pageNum=" + page + "&communityName=" + $("#communityName").val(),
success: function (obj) {
console.log(obj);
console.log(obj.data.rows);
$("#tablist tr").remove();
$(obj.data.rows).each(function () {
var html = "<tr>";
html += "<td>" + trimToEmpty(this.COMMUNITY_NAME) + "</td>";
html += "<td>" + trimToEmpty(this.ADDRESS) + "</td>";
html += "<td>" + trimToEmpty(this.AREA) + "</td>";
html += "<td>" + trimToEmpty(this.HOUSEHOLDS) + "</td>";
html += "<td>" + trimToEmpty(this.JUWEI) + "</td>";
html += "<td>";
html += "<a class='btn btn-info' οnclick='openlayer.openWindows('详情','/ljzqksg/community/formView?id=" + this.ID + "&action=show')'>详情</a>";
html += "<a class='btn btn-warning' οnclick='openlayer.openWindows('编辑','/ljzqksg/community/formView?id=" + this.ID + "&action=edit')'>编辑</a>";
html += " <a class='btn btn-danger' οnclick='delbyid(\"" + this.ID + "\")'>删除</a>";
html += "</td>";
html += "</tr>";
$("#tablist").append(html);
});
refreshPager(obj,page);
}
});
}
function trimToEmpty(obj) {
if (obj == null) {
return "";
}
return obj;
}
function refreshPager(obj,page) {
var pager = $('.pager').data('zui.pager');
pager.set(obj.data.page, obj.data.total, 10);
}
function delbyid(id) {
if (confirm("确定需要删除吗?")) {
$.ajax({
type: "POST",
url: basePath + "community/deleteById" ,
data: "id=" + id,
async: false,
success: function (obj) {
if (obj.status) {
layer.msg("删除成功");
reflush();
} else {
layer.msg("删除失败");
}
reflush();
}
});
}
}
</script>
</html>
添加修改查看页面(form.html)
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh_cn">
<head>
<meta charset="UTF-8">
<title>小区管理</title>
<link rel="stylesheet" type="text/css" th:href="@{/css/bootstrap-datetimepicker.min.css}"/>
</head>
<body>
<form th:action="@{propertypublic/insertPropertyPublic}" method="post" id="saveForm" class="form-horizontal" style="margin-top: 20px">
<input type="hidden" class="form-control" name="id" th:value="${communityBean.id}"/>
<div class="form-group">
<label class="col-sm-2">小区名称</label>
<div class="col-xs-3">
<input class="form-control" name="communityName" th:value="${communityBean.communityName}"/>
</div>
<label class="col-sm-2">所属社区</label>
<div class="col-xs-3">
<select class="form-control" name="juweiCode">
<option th:each="qt:${juweiBean}" th:value="${qt.JUWEICODE}"
th:text="${qt.JUWEINAMEFULL}" th:selected="${communityBean.juweiCode==qt.JUWEICODE}"></option>
</select>
<!-- <input class="form-control" name="communityId" th:value="${journeyBean.communityId}"/>-->
</div>
</div>
<div class="form-group">
<label class="col-sm-2">小区地址</label>
<div class="col-xs-8">
<input class="form-control" name="address" th:value="${communityBean.address}"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2">面 积</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="area" th:value="${communityBean.area}"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2">户 数</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="households" th:value="${communityBean.households}"/>
</div>
</div>
<div style="text-align: center; padding-top: 10px">
<a id="saveBtn" class="btn btn-primary" href="javascript:void(0)" onclick="submitFormv(this)">保存</a>
<a id="closebtn" class="btn" data-dismiss="modal" onclick="openlayer.closeWindows()">关闭</a>
</div>
</form>
</body>
<script type="text/javascript" th:inline="javascript">
var basePath =;
var saveForm = $("#saveForm");
var time = $("#time");
var action = [[${#httpServletRequest.getParameter("action")}]];
console.log(action);
$(function () {
initDefaultSettings(action);
});
function initDefaultSettings(action) {
if (action == "" || action == "show") {
disableTag("saveForm");
}
if (action == "edit" || action == "add") {
$(".form-date").datetimepicker(
{
language: "zh-CN",
weekStart: 1,
todayBtn: 1,
autoclose: 1,
todayHighlight: 1,
startView: 2,
minView: 0,
minuteStep: 1,
forceParse: 0,
format: 'yyyy-mm-dd hh:ii:ss',
});
}
}
function disableTag(formId) {
var form = document.getElementById(formId)
var inputTags = form.getElementsByTagName("input");
for (i = 0; i < inputTags.length; i++) {
if (inputTags[i].type == "radio" || inputTags[i].type == "text" || inputTags[i].type == "password" || inputTags[i].type == "file") {
inputTags[i].readOnly = true;
}
if (inputTags[i].type == "checkbox") {
inputTags[i].disabled = true;
}
}
var selectTags = form.getElementsByTagName("select");
for (i = 0; i < selectTags.length; i++) {
selectTags[i].disabled = true;
}
var buttonTags = form.getElementsByTagName("button");
for (i = 0; i < buttonTags.length; i++) {
buttonTags[i].remove();
}
var textareaTags = form.getElementsByTagName("textarea");
for (i = 0; i < textareaTags.length; i++) {
textareaTags[i].readOnly = true;
}
$("#saveBtn").remove();
}
function submitFormv(obj) {
$.ajax({
type: "POST",
url: basePath + "/community/insertCommunity",
data: $("#saveForm").serialize(),
success: function (data) {
if (data.status) {
$("#saveBtn").hide();
$("#closebtn").show();
layer.msg(data.msg);
}else{
layer.msg(data.msg);
}
}
});
}
</script>
</html>