一篇小区的增删改查
程序员文章站
2022-05-13 15:00:02
...
一篇员工的增删改查
介绍
第一次发博客,我也刚入门不久,学习的途中
我写这个是用springboot来写的
不说废话直接撸码
这是controller层的
package com.system.controller;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
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.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AbcPlot;
import com.ruoyi.system.service.IAbcPlotService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 小区Controller
*
* @author 郑博超
* @date 2020-09-09
*/
@Controller
@RequestMapping("/system/plot")
public class AbcPlotController extends BaseController
{
private String prefix = "system/plot";
@Autowired
private IAbcPlotService abcPlotService;
@RequiresPermissions("system:plot:view")
@GetMapping()
public String plot()
{
return prefix + "/plot";
}
/**
* 查询小区列表
*/
@RequiresPermissions("system:plot:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(AbcPlot abcPlot)
{
startPage();
List<AbcPlot> list = abcPlotService.selectAbcPlotList(abcPlot);
return getDataTable(list);
}
/**
* 导出小区列表
*/
@RequiresPermissions("system:plot:export")
@Log(title = "小区", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ResponseBody
public AjaxResult export(AbcPlot abcPlot)
{
List<AbcPlot> list = abcPlotService.selectAbcPlotList(abcPlot);
ExcelUtil<AbcPlot> util = new ExcelUtil<AbcPlot>(AbcPlot.class);
return util.exportExcel(list, "plot");
}
/**
* 新增小区
*/
@GetMapping("/add")
public String add()
{
return prefix + "/add";
}
/**
* 新增保存小区
*/
@RequiresPermissions("system:plot:add")
@Log(title = "小区", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(AbcPlot abcPlot)
{
return toAjax(abcPlotService.insertAbcPlot(abcPlot));
}
/**
* 修改小区
*/
@GetMapping("/edit/{plotId}")
public String edit(@PathVariable("plotId") String plotId, ModelMap mmap)
{
AbcPlot abcPlot = abcPlotService.selectAbcPlotById(plotId);
mmap.put("abcPlot", abcPlot);
return prefix + "/edit";
}
/**
* 修改保存小区
*/
@RequiresPermissions("system:plot:edit")
@Log(title = "小区", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(AbcPlot abcPlot)
{
return toAjax(abcPlotService.updateAbcPlot(abcPlot));
}
/**
* 删除小区
*/
@RequiresPermissions("system:plot:remove")
@Log(title = "小区", businessType = BusinessType.DELETE)
@PostMapping( "/remove")
@ResponseBody
public AjaxResult remove(String ids)
{
return toAjax(abcPlotService.deleteAbcPlotByIds(ids));
}
}
service层的
package com.system.service;
import java.util.List;
import com.ruoyi.system.domain.AbcPlot;
/**
* 小区Service接口
*
* @author 郑博超
* @date 2020-09-09
*/
public interface IAbcPlotService
{
/**
* 查询小区
*
* @param plotId 小区ID
* @return 小区
*/
public AbcPlot selectAbcPlotById(String plotId);
/**
* 查询小区列表
*
* @param abcPlot 小区
* @return 小区集合
*/
public List<AbcPlot> selectAbcPlotList(AbcPlot abcPlot);
/**
* 新增小区
*
* @param abcPlot 小区
* @return 结果
*/
public int insertAbcPlot(AbcPlot abcPlot);
/**
* 修改小区
*
* @param abcPlot 小区
* @return 结果
*/
public int updateAbcPlot(AbcPlot abcPlot);
/**
* 批量删除小区
*
* @param ids 需要删除的数据ID
* @return 结果
*/
public int deleteAbcPlotByIds(String ids);
/**
* 删除小区信息
*
* @param plotId 小区ID
* @return 结果
*/
public int deleteAbcPlotById(String plotId);
}
serviceimpl层
package com.system.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.AbcPlotMapper;
import com.ruoyi.system.domain.AbcPlot;
import com.ruoyi.system.service.IAbcPlotService;
import com.ruoyi.common.core.text.Convert;
/**
* 小区Service业务层处理
*
* @author 郑博超
* @date 2020-09-09
*/
@Service
public class AbcPlotServiceImpl implements IAbcPlotService
{
@Autowired
private AbcPlotMapper abcPlotMapper;
/**
* 查询小区
*
* @param plotId 小区ID
* @return 小区
*/
@Override
public AbcPlot selectAbcPlotById(String plotId)
{
return abcPlotMapper.selectAbcPlotById(plotId);
}
/**
* 查询小区列表
*
* @param abcPlot 小区
* @return 小区
*/
@Override
public List<AbcPlot> selectAbcPlotList(AbcPlot abcPlot)
{
return abcPlotMapper.selectAbcPlotList(abcPlot);
}
/**
* 新增小区
*
* @param abcPlot 小区
* @return 结果
*/
@Override
public int insertAbcPlot(AbcPlot abcPlot)
{
return abcPlotMapper.insertAbcPlot(abcPlot);
}
/**
* 修改小区
*
* @param abcPlot 小区
* @return 结果
*/
@Override
public int updateAbcPlot(AbcPlot abcPlot)
{
return abcPlotMapper.updateAbcPlot(abcPlot);
}
/**
* 删除小区对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteAbcPlotByIds(String ids)
{
return abcPlotMapper.deleteAbcPlotByIds(Convert.toStrArray(ids));
}
/**
* 删除小区信息
*
* @param plotId 小区ID
* @return 结果
*/
@Override
public int deleteAbcPlotById(String plotId)
{
return abcPlotMapper.deleteAbcPlotById(plotId);
}
}
mapper层
package com.system.mapper;
import java.util.List;
import com.system.domain.AbcPlot;
/**
* 小区Mapper接口
*
* @author 郑博超
* @date 2020-09-09
*/
public interface AbcPlotMapper
{
/**
* 查询小区
*
* @param plotId 小区ID
* @return 小区
*/
public AbcPlot selectAbcPlotById(String plotId);
/**
* 查询小区列表
*
* @param abcPlot 小区
* @return 小区集合
*/
public List<AbcPlot> selectAbcPlotList(AbcPlot abcPlot);
/**
* 新增小区
*
* @param abcPlot 小区
* @return 结果
*/
public int insertAbcPlot(AbcPlot abcPlot);
/**
* 修改小区
*
* @param abcPlot 小区
* @return 结果
*/
public int updateAbcPlot(AbcPlot abcPlot);
/**
* 删除小区
*
* @param plotId 小区ID
* @return 结果
*/
public int deleteAbcPlotById(String plotId);
/**
* 批量删除小区
*
* @param plotIds 需要删除的数据ID
* @return 结果
*/
public int deleteAbcPlotByIds(String[] plotIds);
}
xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper SYSTEM "http://mybatis.org/dtd/mybatis-3-mapper.dtd" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN">
-<mapper namespace="com.system.mapper.AbcPlotMapper">
-<resultMap id="AbcPlotResult" type="AbcPlot">
<result column="plot_id" property="plotId"/>
<result column="plot_company" property="plotCompany"/>
<result column="plot_site" property="plotSite"/>
<result column="plot_households" property="plotHouseholds"/>
<result column="plot_gate" property="plotGate"/>
<result column="plot_area" property="plotArea"/>
<result column="company_id" property="companyId"/>
</resultMap>
<sql id="selectAbcPlotVo">select plot_id, plot_company, plot_site, plot_households, plot_gate, plot_area, company_id from abc_plot </sql>
-<select id="selectAbcPlotList" resultMap="AbcPlotResult" parameterType="AbcPlot">
<include refid="selectAbcPlotVo"/>
-<where>
<if test="plotId != null and plotId != ''"> and plot_id = #{plotId}</if>
<if test="plotCompany != null and plotCompany != ''"> and plot_company = #{plotCompany}</if>
<if test="plotSite != null and plotSite != ''"> and plot_site = #{plotSite}</if>
<if test="plotHouseholds != null "> and plot_households = #{plotHouseholds}</if>
<if test="plotGate != null "> and plot_gate = #{plotGate}</if>
<if test="plotArea != null "> and plot_area = #{plotArea}</if>
<if test="companyId != null and companyId != ''"> and company_id = #{companyId}</if>
</where>
</select>
-<select id="selectAbcPlotById" resultMap="AbcPlotResult" parameterType="String">
<include refid="selectAbcPlotVo"/>
where plot_id = #{plotId}
</select>
-<insert id="insertAbcPlot" parameterType="AbcPlot">
insert into abc_plot
-<trim suffixOverrides="," suffix=")" prefix="(">
<if test="plotId != null">plot_id,</if>
<if test="plotCompany != null">plot_company,</if>
<if test="plotSite != null">plot_site,</if>
<if test="plotHouseholds != null">plot_households,</if>
<if test="plotGate != null">plot_gate,</if>
<if test="plotArea != null">plot_area,</if>
<if test="companyId != null">company_id,</if>
</trim>
-<trim suffixOverrides="," suffix=")" prefix="values (">
<if test="plotId != null">#{plotId},</if>
<if test="plotCompany != null">#{plotCompany},</if>
<if test="plotSite != null">#{plotSite},</if>
<if test="plotHouseholds != null">#{plotHouseholds},</if>
<if test="plotGate != null">#{plotGate},</if>
<if test="plotArea != null">#{plotArea},</if>
<if test="companyId != null">#{companyId},</if>
</trim>
</insert>
-<update id="updateAbcPlot" parameterType="AbcPlot">
update abc_plot
-<trim suffixOverrides="," prefix="SET">
<if test="plotCompany != null">plot_company = #{plotCompany},</if>
<if test="plotSite != null">plot_site = #{plotSite},</if>
<if test="plotHouseholds != null">plot_households = #{plotHouseholds},</if>
<if test="plotGate != null">plot_gate = #{plotGate},</if>
<if test="plotArea != null">plot_area = #{plotArea},</if>
<if test="companyId != null">company_id = #{companyId},</if>
</trim>
where plot_id = #{plotId}
</update>
<delete id="deleteAbcPlotById" parameterType="String">delete from abc_plot where plot_id = #{plotId} </delete>
-<delete id="deleteAbcPlotByIds" parameterType="String">
delete from abc_plot where plot_id in
<foreach close=")" separator="," open="(" collection="array" item="plotId">#{plotId} </foreach>
</delete>
</mapper>
实体类
package com.system.domain;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 小区对象 abc_plot
*
* @author 郑博超
* @date 2020-09-09
*/
public class AbcPlot extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** null */
@Excel(name = "null")
private String plotId;
/** 公司小区 */
@Excel(name = "公司小区")
private String plotCompany;
/** 小区地址 */
@Excel(name = "小区地址")
private String plotSite;
/** 用户数 */
@Excel(name = "用户数")
private Long plotHouseholds;
/** 大门数 */
@Excel(name = "大门数")
private Long plotGate;
/** 建筑面积 */
@Excel(name = "建筑面积")
private Long plotArea;
/** 公司id */
@Excel(name = "公司id")
private String companyId;
public void setPlotId(String plotId)
{
this.plotId = plotId;
}
public String getPlotId()
{
return plotId;
}
public void setPlotCompany(String plotCompany)
{
this.plotCompany = plotCompany;
}
public String getPlotCompany()
{
return plotCompany;
}
public void setPlotSite(String plotSite)
{
this.plotSite = plotSite;
}
public String getPlotSite()
{
return plotSite;
}
public void setPlotHouseholds(Long plotHouseholds)
{
this.plotHouseholds = plotHouseholds;
}
public Long getPlotHouseholds()
{
return plotHouseholds;
}
public void setPlotGate(Long plotGate)
{
this.plotGate = plotGate;
}
public Long getPlotGate()
{
return plotGate;
}
public void setPlotArea(Long plotArea)
{
this.plotArea = plotArea;
}
public Long getPlotArea()
{
return plotArea;
}
public void setCompanyId(String companyId)
{
this.companyId = companyId;
}
public String getCompanyId()
{
return companyId;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("plotId", getPlotId())
.append("plotCompany", getPlotCompany())
.append("plotSite", getPlotSite())
.append("plotHouseholds", getPlotHouseholds())
.append("plotGate", getPlotGate())
.append("plotArea", getPlotArea())
.append("companyId", getCompanyId())
.toString();
}
}
cv大法后结合自己的前段便可以使用
第一次写博客
上一篇: Mysql大法--增删改查
下一篇: 滑动的验证码