1.controller层
package com.eastcom.party.controller;
import java.util.HashMap;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.eastcom.common.controller.BaseController;
import com.eastcom.party.domain.PartyBuilDO;
import com.eastcom.party.domain.PartyBuilParamDO;
import com.eastcom.party.service.PartyBuilService;
import com.eastcom.common.utils.R;
/**
* 党日活动
*
* @author xiazf
* @email [email protected]
* @date 2020-03-18 13:38:10
*/
@Controller
@RequestMapping("/party/partyBuil")
public class PartyBuilController extends BaseController {
@Autowired
private PartyBuilService partyBuilService;
@GetMapping("/view")
@RequiresPermissions("party:partyBuil:view")
public ModelAndView view(Integer id) {
Map
map.put("userDO", getUser());
map.put("partyBuilDO", partyBuilService.query(id, getUser()));
return new ModelAndView("party/partyBuil", map);
}
@GetMapping("/view-list")
@RequiresPermissions("party:partyBuil:view-list")
public ModelAndView viewList() {
Map
map.put("userDO", getUser());
return new ModelAndView("party/partyBuilList", map);
}
@ResponseBody
@GetMapping()
@RequiresPermissions("party:partyBuil:queryList")
public R queryList(PartyBuilParamDO queryParamDO) {
return R.success(partyBuilService.queryList(queryParamDO, getUser()));
}
@ResponseBody
@GetMapping("/{id}")
@RequiresPermissions("party:partyBuil:query")
public R query(@PathVariable Integer id) {
return R.success(partyBuilService.query(id, getUser()));
}
@ResponseBody
@PostMapping()
@RequiresPermissions("party:partyBuil:insert")
public R insert(@Validated PartyBuilDO partyBuilDO, BindingResult result) {
validate(result);
return R.success(partyBuilService.insert(partyBuilDO, getUser()));
}
@ResponseBody
@PutMapping("/{id}")
@RequiresPermissions("party:partyBuil:update")
public R update(@Validated PartyBuilDO partyBuilDO, BindingResult result) {
validate(result);
return R.success(partyBuilService.update(partyBuilDO, getUser()));
}
@ResponseBody
@DeleteMapping("/{id}")
@RequiresPermissions("party:partyBuil:delete")
public R delete(PartyBuilDO partyBuilDO) {
return R.success(partyBuilService.delete(partyBuilDO, getUser()));
}
}
所关联的是BaseController是在工具类包中
package com.eastcom.common.controller;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import com.eastcom.common.domain.PagingList;
import com.eastcom.common.domain.UserDO;
import com.eastcom.common.exception.ExceptionBuilder;
import com.eastcom.common.spring.BeanConverter;
import com.eastcom.common.utils.ShiroUtils;
import com.eastcom.common.utils.UtilJWT;
@Controller
public class BaseController {
public String session_user_flag = "user";
@Autowired
private BeanConverter beanConverter;
/**
* 获取Shiro中的登录用户,用于后台管理系统的用户获取
*
* @return
*/
public UserDO getUser() {
UserDO userDO = ShiroUtils.getUser();
userDO.setPassword("");
return userDO;
}
/**
* 获取请求中的Token,生成UserDO对象
*
* @param request
* @return
*/
public UserDO getUser(HttpServletRequest request) {
return UtilJWT.unsign(request.getHeader("token"), UserDO.class);
}
public Long getUserId() {
return getUser().getUserId();
}
public String getUsername() {
return getUser().getUsername();
}
protected void validate(BindingResult result) {
if (result.hasErrors()) {
throw ExceptionBuilder.service(result);
}
}
public String getWXOpenid(HttpServletRequest request) {
return request.getHeader("openid");
}
public String getDDUserid(HttpServletRequest request) {
return request.getHeader("userid");
}
public
return beanConverter.convert(source, clz);
}
public source, Class
return beanConverter.convert(source, clz);
}
public source, Class
return beanConverter.convert(source, clz);
}
public
source.setRows(beanConverter.convert(source.getRows(), clz));
return source;
}
}
2.注入的service层是
package com.eastcom.party.service;
import com.eastcom.common.domain.PagingList;
import com.eastcom.common.domain.QueryParamDO;
import com.eastcom.common.domain.UserDO;
import com.eastcom.party.domain.PartyBuilDO;
/**
* 党日活动/志愿服务/重点部署/联村会议
*
* @author xiazf
* @email [email protected]
* @date 2020-03-18 13:38:10
*/
public interface PartyBuilService {
public PagingList queryList(QueryParamDO queryParamDO, UserDO userDO);
public PartyBuilDO query(Integer id, UserDO userDO);
public PartyBuilDO insert(PartyBuilDO partyBuilDO, UserDO userDO);
public PartyBuilDO update(PartyBuilDO partyBuilDO, UserDO userDO);
public PartyBuilDO delete(PartyBuilDO partyBuilDO, UserDO userDO);
}
这层有查询参数的实体类QueryParamDO也有具体的实体类PartyBuilDO还有user的实体类UserDO
3.impl层
package com.eastcom.party.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.eastcom.party.dao.PartyBuilDao;
import com.eastcom.party.domain.PartyBuilDO;
import com.eastcom.party.service.PartyBuilService;
import com.eastcom.common.domain.PagingList;
import com.eastcom.common.domain.QueryParamDO;
import com.eastcom.common.domain.UserDO;
import com.eastcom.common.exception.ExceptionBuilder;
@Service
public class PartyBuilServiceImpl implements PartyBuilService {
@Autowired
private PartyBuilDao partyBuilDao;
@Override
public PagingList queryList(QueryParamDO queryParamDO, UserDO userDO) {
int total = partyBuilDao.queryListCount(queryParamDO, userDO);
List
return PagingList.create(total, rows);
}
@Override
public PartyBuilDO query(Integer id, UserDO userDO) {
return partyBuilDao.query(id, userDO);
}
@Override
public PartyBuilDO insert(PartyBuilDO partyBuilDO, UserDO userDO) {
partyBuilDao.insert(partyBuilDO, userDO);
return partyBuilDO;
}
@Override
public PartyBuilDO update(PartyBuilDO partyBuilDO, UserDO userDO) {
PartyBuilDO partyBuilDB = partyBuilDao.query(partyBuilDO.getId(), userDO);
if (partyBuilDB == null) {
throw ExceptionBuilder.service("无效的数据");
}
partyBuilDao.update(partyBuilDO, userDO);
return partyBuilDO;
}
@Override
public PartyBuilDO delete(PartyBuilDO partyBuilDO, UserDO userDO) {
PartyBuilDO partyBuilDB = partyBuilDao.query(partyBuilDO.getId(), userDO);
if (partyBuilDB == null) {
throw ExceptionBuilder.service("无效的数据");
}
partyBuilDao.delete(partyBuilDO, userDO);
return partyBuilDO;
}}
这层注入的是dao层PartyBuilDao
4.dao层
package com.eastcom.party.dao;
import com.eastcom.party.domain.PartyBuilDO;
import java.util.List;
import com.eastcom.common.domain.QueryParamDO;
import com.eastcom.common.domain.UserDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* zhiyuanfuwu
* @author xiazf
* @email [email protected]
* @date 2020-03-18 13:38:10
*/
@Mapper
public interface PartyBuilDao {
public PartyBuilDO query(@Param("id") Integer id, @Param("userDO") UserDO userDO);
public int queryListCount(@Param("queryParamDO") QueryParamDO queryParamDO, @Param("userDO") UserDO userDO);
public List
public int insert(@Param("partyBuilDO") PartyBuilDO partyBuilDO, @Param("userDO") UserDO userDO);
public int update(@Param("partyBuilDO") PartyBuilDO partyBuilDO, @Param("userDO") UserDO userDO);
public int delete(@Param("partyBuilDO") PartyBuilDO partyBuilDO, @Param("userDO") UserDO userDO);
public int deleteBatch(List
}
5.因为在页面中有条件筛选所以添加两个实体类PartyBuilParamDO和PartyBuilParamFilterDO
package com.eastcom.party.domain;
import com.eastcom.common.domain.QueryParamDO;
/**
* 党日活动
*
* @author xiazf
* @email [email protected]
* @date 2020-03-18 13:38:10
*/
public class PartyBuilParamDO extends QueryParamDO {
private PartyBuilParamFilterDO filter;
public PartyBuilParamFilterDO getFilter() {
return filter;
}
public void setFilter(PartyBuilParamFilterDO filter) {
this.filter = filter;
}
}
package com.eastcom.party.domain;
/**
* 党日活动
*
* @author xiazf
* @email [email protected]
* @date 2020-03-18 13:38:10
*/
public class PartyBuilParamFilterDO {
private String title;
private String address;
private String gridName;
private String longitude;
private Integer latitude;
private String content;
private String createTimeStart;
private String createTimeClose;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getGridName() {
return gridName;
}
public void setGridName(String gridName) {
this.gridName = gridName;
}
public String getLongitude() {
return longitude;
}
public void setLongitude(String longitude) {
this.longitude = longitude;
}
public Integer getLatitude() {
return latitude;
}
public void setLatitude(Integer latitude) {
this.latitude = latitude;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getCreateTimeStart() {
return createTimeStart;
}
public void setCreateTimeStart(String createTimeStart) {
this.createTimeStart = createTimeStart;
}
public String getCreateTimeClose() {
return createTimeClose;
}
public void setCreateTimeClose(String createTimeClose) {
this.createTimeClose = createTimeClose;
}
}
和他自己的实体类
package com.eastcom.party.domain;
import java.io.Serializable;
import java.util.Date;
import javax.validation.constraints.NotBlank;
import com.eastcom.common.validator.group.GroupOne;
import com.eastcom.common.validator.group.GroupTwo;
import com.eastcom.common.validator.group.Insert;
import com.eastcom.common.validator.group.Update;
/**
* 党日活动/志愿服务/重点部署/联村会议
*
* @author lyh
* @email [email protected]
* @date 2020-03-19 14:24:10
*/
public class PartyBuilDO implements Serializable {
private static final long serialVersionUID = 1L;
//
private Integer id;
//活动名称
@NotBlank(message = "活动名称不能为空", groups = {Insert.class, Update.class, GroupOne.class, GroupTwo.class})
private String title;
//网格id
private Long gridId;
//网格名称
@NotBlank(message = "网格名称不能为空", groups = {Insert.class, Update.class, GroupOne.class, GroupTwo.class})
private String gridName;
//上报地址
@NotBlank(message = "上报地址不能为空", groups = {Insert.class, Update.class, GroupOne.class, GroupTwo.class})
private String address;
//经度
@NotBlank(message = "经度不能为空", groups = {Insert.class, Update.class, GroupOne.class, GroupTwo.class})
private String longitude;
//纬度
@NotBlank(message = "纬度不能为空", groups = {Insert.class, Update.class, GroupOne.class, GroupTwo.class})
private String latitude;
//报送内容
@NotBlank(message = "报送内容不能为空", groups = {Insert.class, Update.class, GroupOne.class, GroupTwo.class})
private String content;
//类别-1党日活动/2志愿服务/3重点部署/4联村会议
private Integer type;
//创建时间
private Date createTime;
//创建者
private Integer createUserId;
//创建钉钉Id
private Long createDdId;
//更新时间
private Date updateTime;
//更新者
private Integer updateUserId;
//更新钉钉Id
private Long updateDdId;
//重点部署对应的任务Id
private Integer taskId;
private Integer partyId;
private String person;
public Integer getPartyId() {
return partyId;
}
public void setPartyId(Integer partyId) {
this.partyId = partyId;
}
public String getPerson() {
return person;
}
public void setPerson(String person) {
this.person = person;
}
/**
* 设置:
*/
public void setId(Integer id) {
this.id = id;
}
/**
* 获取:
*/
public Integer getId() {
return id;
}
/**
* 设置:活动名称
*/
public void setTitle(String title) {
this.title = title;
}
/**
* 获取:活动名称
*/
public String getTitle() {
return title;
}
/**
* 设置:网格id
*/
public void setGridId(Long gridId) {
this.gridId = gridId;
}
/**
* 获取:网格id
*/
public Long getGridId() {
return gridId;
}
/**
* 设置:网格名称
*/
public void setGridName(String gridName) {
this.gridName = gridName;
}
/**
* 获取:网格名称
*/
public String getGridName() {
return gridName;
}
/**
* 设置:上报地址
*/
public void setAddress(String address) {
this.address = address;
}
/**
* 获取:上报地址
*/
public String getAddress() {
return address;
}
/**
* 设置:经度
*/
public void setLongitude(String longitude) {
this.longitude = longitude;
}
/**
* 获取:经度
*/
public String getLongitude() {
return longitude;
}
/**
* 设置:纬度
*/
public void setLatitude(String latitude) {
this.latitude = latitude;
}
/**
* 获取:纬度
*/
public String getLatitude() {
return latitude;
}
/**
* 设置:报送内容
*/
public void setContent(String content) {
this.content = content;
}
/**
* 获取:报送内容
*/
public String getContent() {
return content;
}
/**
* 设置:类别-1党日活动/2志愿服务/3重点部署/4联村会议
*/
public void setType(Integer type) {
this.type = type;
}
/**
* 获取:类别-1党日活动/2志愿服务/3重点部署/4联村会议
*/
public Integer getType() {
return type;
}
/**
* 设置:创建时间
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* 获取:创建时间
*/
public Date getCreateTime() {
return createTime;
}
/**
* 设置:创建者
*/
public void setCreateUserId(Integer createUserId) {
this.createUserId = createUserId;
}
/**
* 获取:创建者
*/
public Integer getCreateUserId() {
return createUserId;
}
/**
* 设置:创建钉钉Id
*/
public void setCreateDdId(Long createDdId) {
this.createDdId = createDdId;
}
/**
* 获取:创建钉钉Id
*/
public Long getCreateDdId() {
return createDdId;
}
/**
* 设置:更新时间
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
* 获取:更新时间
*/
public Date getUpdateTime() {
return updateTime;
}
/**
* 设置:更新者
*/
public void setUpdateUserId(Integer updateUserId) {
this.updateUserId = updateUserId;
}
/**
* 获取:更新者
*/
public Integer getUpdateUserId() {
return updateUserId;
}
/**
* 设置:更新钉钉Id
*/
public void setUpdateDdId(Long updateDdId) {
this.updateDdId = updateDdId;
}
/**
* 获取:更新钉钉Id
*/
public Long getUpdateDdId() {
return updateDdId;
}
/**
* 设置:重点部署对应的任务Id
*/
public void setTaskId(Integer taskId) {
this.taskId = taskId;
}
/**
* 获取:重点部署对应的任务Id
*/
public Integer getTaskId() {
return taskId;
}
}
然后是mapper层因为只有查询和修改所以我没写插入的sql
and
(
title like concat('%', #{queryParamDO.search}, '%')
)
and title like concat('%', #{queryParamDO.filter.title}, '%')
and address like concat('%', #{queryParamDO.filter.address}, '%')
and grid_name like concat('%', #{queryParamDO.filter.gridName}, '%')
and longitude like concat('%', #{queryParamDO.filter.longitude}, '%')
and latitude like concat('%', #{queryParamDO.filter.latitude}, '%')
and content like concat('%', #{queryParamDO.filter.content}, '%')
and create_time >= #{queryParamDO.filter.createTimeStart}
and create_time <= #{queryParamDO.filter.createTimeClose}
update pjdj_party_building
`title` = #{partyBuilDO.title},
`address` = #{partyBuilDO.address},
`content` = #{partyBuilDO.content}
where id = #{partyBuilDO.id}
delete from pjdj_party_building where id = #{partyBuilDO.id}
delete from pjdj_party_building where id in
#{item.id}
js层
partyBuil.js
$(function() {
Article.init({
url : '../../party/partyBuil'
});
});
partyBuilList.js
$(function() {
PartyBuil.init();
$('#btn_insert').on('click', function() {
PartyBuil.doInsert();
});
$('#btn_update').on('click', function() {
PartyBuil.doUpdate();
});
$('#btn_delete').on('click', function() {
Pervice.doDelete();
});
});
PartyBuil = {
init : function() {
SP.table.bootstrap('#table', {
url : '../../party/partyBuil',
queryParams : function(params) {
return this.getAdvancedSearchParams({
search : this.searchText,
offset : params.offset,
limit : params.limit,
sortName : this.sortName,
sortOrder : this.sortOrder
});
},
toolbar : "#toolbar",
search : true,
formatSearch : function() {
return '活动名称';
},
advancedSearch : true,
showRefresh : true,
showColumns : true,
showToggle : true,
showExport : true,
exportTitle : '党日活动',
sortName : 'id',
sortOrder : 'desc',
columns : [ {
radio : true
}, {
field : 'title',
title : '活动名称',
sortable : true,
searchable : true
},
/*{
field : 'gridId',
title : '网格Id',
sortable : true,
searchable : true
},*/
{
field : 'gridName',
title : '网格名称',
sortable : true,
searchable : true
},{
field : 'address',
title : '详细地址',
sortable : true,
searchable : true
},{
field : 'longitude',
title : '经度',
sortable : true,
searchable : true
},{
field : 'latitude',
title : '纬度',
sortable : true,
searchable : true
},{
field : 'content',
title : '内容',
sortable : true,
searchable : true
},/*{
field : 'createUserId',
title : '创建人',
sortable : true,
searchable : true
},*/ {
field : 'createTime',
title : '创建时间',
sortable : true,
searchable : true,
searchOptions : {
type : 'date-interval'
}
}, {
title : '操作',
searchable : false,
exportable : false,
align : 'center',
formatter : function(value, row, index) {
var p = SP.fn.sprintf('图片 ', AppData.permission.s_update ? '' : 'hidden');
var u = SP.fn.sprintf('编辑 ', AppData.permission.s_update ? '' : 'hidden');
var d = SP.fn.sprintf('删除 ', AppData.permission.s_delete ? '' : 'hidden')
return p + u + d;
},
events : {
'click [data-options="upload"]:not(.disabled)' : function(e, value, row, index) {
PartyBuil.doUpload(row);
},
'click [data-options="update"]:not(.disabled)' : function(e, value, row, index) {
PartyBuil.doUpdate(row);
},
'click [data-options="delete"]:not(.disabled)' : function(e, value, row, index) {
PartyBuil.doDelete(row);
}
}
} ],
onDblClickCell : function(field, value, row, $element) {}
});
},
doInsert : function() {
SP.form.resetValid('#partyBuil');
SP.modal.show('#modal', {
title : '新增党日活动',
yes : function(obj) {
if (SP.form.isValid('#partyBuil')) {
SP.http.ajaxPost({
url : '../../party/partyBuil',
data : SP.form.getValue('#partyBuil'),
success : function(data) {
SP.modal.alert(data.msg, function() {
if (data.code == 0) {
SP.table.bootstrap.method('#table', 'refresh');
SP.modal.hide('#modal');
}
}, data.code == 0);
}
});
}
}
});
},
doUpload : function(row) {
row = row || SP.table.bootstrap.method('#table', 'getSelections')[0];
if (!row) {
SP.modal.alert('请选择一条需要上传的数据!');
return;
}
SP.modal.fileinput({
id : 'image_uploader',
sid : 200600,
tid : 210,
pid : row.id,
showPreview : false,
dataPreview : true,
title : '党日活动图片管理',
remarks : '建议图片宽度:500px,长度:200px;'
});
},
doUpdate : function(row) {
row = row || SP.table.bootstrap.method('#table', 'getSelections')[0];
if (!row) {
SP.modal.alert('请选择一条需要编辑的数据!');
return;
}
SP.form.resetValid('#partyBuil');
SP.form.setValue('#partyBuil', row);
SP.modal.show('#modal', {
title : '编辑党日活动',
yes : function(obj) {
if (SP.form.isValid('#partyBuil')) {
SP.http.ajaxPut({
url : '../../party/partyBuil/' + row.id,
data : SP.form.getValue('#partyBuil'),
success : function(data) {
SP.modal.alert(data.msg, function() {
if (data.code == 0) {
SP.table.bootstrap.method('#table', 'refresh');
SP.modal.hide('#modal');
}
}, data.code == 0);
}
});
}
}
});
},
doDelete : function(row) {
row = row || SP.table.bootstrap.method('#table', 'getSelections')[0];
if (!row) {
SP.modal.alert('请选择一条需要删除的数据!');
return;
}
SP.modal.confirm('是否删除选中的数据?', function() {
SP.http.ajaxDelete({
url : '../../party/partyBuil/' + row.id,
success : function(data) {
SP.modal.alert(data.msg, function() {
if (data.code == 0) {
SP.table.bootstrap.method('#table', 'refresh');
}
}, data.code == 0);
}
});
});
}
}
html层
partyBuil.html
partyBuilList.html