提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
SpringBoot-社区管理系统
一、需求分析
二、功能分析
三、开发流程
1.创建数据库
CREATE DATABASE `MyCommunity`;
USE `MyCommunity`;
DROP TABLE IF EXISTS `tb_activity`;
CREATE TABLE `tb_activity` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '活动ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`title` varchar(100) DEFAULT NULL COMMENT '活动标题',
`address` varchar(200) DEFAULT NULL COMMENT '活动地点',
`organizer` varchar(100) DEFAULT NULL COMMENT '举办单位',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
`start_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '活动开始时间',
`end_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '活动截止时间',
`status` char(1) DEFAULT '0' COMMENT '状态:0-活动未开始(默认),1-活动进行中,2-活动已结束',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='活动表';
DROP TABLE IF EXISTS `tb_building`;
CREATE TABLE `tb_building` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '楼栋ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`name` varchar(50) DEFAULT NULL COMMENT '栋数名称',
`total_households` int(11) DEFAULT NULL COMMENT '总户数',
`description` varchar(500) DEFAULT NULL COMMENT '描述',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='楼栋表';
DROP TABLE IF EXISTS `tb_car`;
CREATE TABLE `tb_car` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '车辆ID',
`picture` varchar(100) DEFAULT NULL COMMENT '车辆照片',
`owner_id` int(11) DEFAULT NULL COMMENT '所属成员(业主)',
`color` varchar(10) DEFAULT NULL COMMENT '车辆颜色',
`car_number` varchar(20) DEFAULT NULL COMMENT '车牌号',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='车辆表';
DROP TABLE IF EXISTS `tb_charge_detail`;
CREATE TABLE `tb_charge_detail` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '收费明细ID',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`charge_item_id` int(11) DEFAULT NULL COMMENT '收费项目ID',
`charge_item_name` varchar(50) DEFAULT NULL COMMENT '收费项目名称',
`contractor` varchar(50) DEFAULT NULL COMMENT '承办人名称',
`telephone` int(20) DEFAULT NULL COMMENT '承办人联系电话',
`pay_money` int(11) DEFAULT NULL COMMENT '应收金额(¥),单位分',
`actual_money` int(11) DEFAULT NULL COMMENT '实收金额(¥),单位分',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
`pay_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '缴费时间',
`status` char(1) DEFAULT '0' COMMENT '状态:0-生效中(默认),1-已过期',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='收费名细表';
DROP TABLE IF EXISTS `tb_charge_item`;
CREATE TABLE `tb_charge_item` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '收费项目ID',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`code` varchar(20) DEFAULT NULL COMMENT '收费编号',
`name` varchar(50) DEFAULT NULL COMMENT '项目名称',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
`money` int(11) DEFAULT NULL COMMENT '项目收费金额(年),单位分',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='收费项目表';
DROP TABLE IF EXISTS `tb_community`;
CREATE TABLE `tb_community` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '小区id',
`code` varchar(20) NOT NULL COMMENT '小区编号',
`name` varchar(50) NOT NULL COMMENT '小区名称',
`address` varchar(200) DEFAULT NULL COMMENT '坐落地址',
`area` double DEFAULT NULL COMMENT '占地面积(m2)',
`total_buildings` int(11) DEFAULT NULL COMMENT '总栋数',
`total_households` int(11) DEFAULT NULL COMMENT '总户数',
`greening_rate` int(11) DEFAULT NULL COMMENT '绿化率(%)',
`thumbnail` varchar(200) DEFAULT NULL COMMENT '缩略图',
`developer` varchar(100) DEFAULT NULL COMMENT '开发商名称',
`estate_company` varchar(100) DEFAULT NULL COMMENT '物业公司名称',
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NULL DEFAULT NULL COMMENT '更新时间',
`status` char(1) DEFAULT '0' COMMENT '状态:0-启用(默认),1-不启用',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8 COMMENT='小区表';
insert into `tb_community`(`id`,`code`,`name`,`address`,`area`,`total_buildings`,`total_households`,`greening_rate`,`thumbnail`,`developer`,`estate_company`,`create_time`,`update_time`,`status`) values (1,'HX19960101001','化纤小区','历城区花园路5号',22222,66,2432,30,'/fileupload/d2cea885-a986-463a-97da-7073c9e6fbf6.jpg','济南齐鲁化纤集团有限责任公司','上海新长宁集团新华物业有限公司','2020-12-13 09:12:04','2020-12-13 09:26:12','0');
insert into `tb_community`(`id`,`code`,`name`,`address`,`area`,`total_buildings`,`total_households`,`greening_rate`,`thumbnail`,`developer`,`estate_company`,`create_time`,`update_time`,`status`) values (2,'DH19960101002','东风小区','历城区花园路6号',33000,50,2222,40,'/images/dongfeng.jpg','济南齐鲁化纤集团有限责任公司','上海新长宁集团新华物业有限公司','2020-12-13 09:24:42','2020-12-13 09:26:14','0');
insert into `tb_community`(`id`,`code`,`name`,`address`,`area`,`total_buildings`,`total_households`,`greening_rate`,`thumbnail`,`developer`,`estate_company`,`create_time`,`update_time`,`status`) values (3,'BH19960101003','百花小区','历城区花园路7号',44444,88,3000,50,'/fileupload/e6daae7d-17f6-4053-9e44-81cf5a4c5d82.jpg','济南齐鲁化纤集团有限责任公司','上海新长宁集团新华物业有限公司','2020-12-13 09:24:42','2020-12-13 09:24:42','0');
insert into `tb_community`(`id`,`code`,`name`,`address`,`area`,`total_buildings`,`total_households`,`greening_rate`,`thumbnail`,`developer`,`estate_company`,`create_time`,`update_time`,`status`) values (28,'JYHF20160101001','金域华府','齐鲁软件园',66666,66,2195,35,'/fileupload/1faae278-4fc7-4561-b1bf-3770f0a7c75c.jpg','万达地产集团','万科物业','2020-12-14 19:29:48',NULL,'0');
DROP TABLE IF EXISTS `tb_complaint`;
CREATE TABLE `tb_complaint` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '投诉ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`owner_id` int(11) DEFAULT NULL COMMENT '投诉人员(业主)ID',
`owner_name` varchar(40) DEFAULT NULL COMMENT '投诉人员(业主)名称',
`description` varchar(500) DEFAULT NULL COMMENT '投诉具体描述',
`reason` varchar(100) DEFAULT NULL COMMENT '投诉事由',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
`status` char(1) DEFAULT '0' COMMENT '状态:0-未受理,1-已受理(默认),2-已处理完毕',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='投诉表';
DROP TABLE IF EXISTS `tb_device`;
CREATE TABLE `tb_device` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '设备ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`code` varchar(20) DEFAULT NULL COMMENT '设备编号',
`name` varchar(50) DEFAULT NULL COMMENT '设备名称',
`brand` varchar(40) DEFAULT NULL COMMENT '设备品牌',
`unit_price` int(11) DEFAULT NULL COMMENT '购买单价(¥),单位分',
`num` int(11) DEFAULT NULL COMMENT '购买数量',
`expected_useful_life` int(11) DEFAULT NULL COMMENT '预计使用年限(年)',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
`purchase_date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '购买日期',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='设备表';
DROP TABLE IF EXISTS `tb_estate_manager`;
CREATE TABLE `tb_estate_manager` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '物业管理人员ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`login_name` varchar(20) DEFAULT NULL COMMENT '登录名:登录时使用的名称',
`name` varchar(50) DEFAULT NULL COMMENT '真实名称',
`password` varchar(60) DEFAULT NULL COMMENT '密码',
`telephone` int(20) DEFAULT NULL COMMENT '手机',
`email` varchar(50) DEFAULT NULL COMMENT '邮箱',
`role_id` int(11) DEFAULT '0' COMMENT '角色ID:0-普通用户(默认0),1-管理员用户',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='物业管理人员表';
insert into `tb_estate_manager`(`id`,`community_name`,`community_id`,`login_name`,`name`,`password`,`telephone`,`email`,`role_id`,`create_time`,`update_time`) values (1,'化纤小区',1,'15900000000','张三','123456',2147483647,'123@163.com',0,'2020-12-14 10:17:49','2020-12-14 10:17:49');
insert into `tb_estate_manager`(`id`,`community_name`,`community_id`,`login_name`,`name`,`password`,`telephone`,`email`,`role_id`,`create_time`,`update_time`) values (2,'百花小区',3,'15911111111','李四','123456',2147483647,'456@163.com',0,'2020-12-14 10:17:55','2020-12-14 10:17:55');
insert into `tb_estate_manager`(`id`,`community_name`,`community_id`,`login_name`,`name`,`password`,`telephone`,`email`,`role_id`,`create_time`,`update_time`) values (3,'东风小区',2,'15922222222','王五','123456',2147483647,'789@163.com',0,'2020-12-14 10:18:03','2020-12-14 10:18:03');
DROP TABLE IF EXISTS `tb_house`;
CREATE TABLE `tb_house` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '房屋ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`building_name` varchar(50) DEFAULT NULL COMMENT '所属栋数名称',
`building_id` int(11) DEFAULT NULL COMMENT '所属栋数ID',
`code` varchar(50) DEFAULT NULL COMMENT '房产编码',
`name` varchar(100) DEFAULT NULL COMMENT '房产名称',
`owner_id` int(11) DEFAULT NULL COMMENT '户主(业主)ID',
`owner_name` varchar(50) DEFAULT NULL COMMENT '户主(业主)名称',
`telephone` int(20) DEFAULT NULL COMMENT '联系方式',
`room_num` int(11) DEFAULT NULL COMMENT '房间数',
`unit` int(2) DEFAULT NULL COMMENT '单元',
`floor` int(3) DEFAULT NULL COMMENT '楼层',
`description` varchar(500) DEFAULT NULL COMMENT '描述',
`live_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '入住时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='房屋表';
DROP TABLE IF EXISTS `tb_letter`;
CREATE TABLE `tb_letter` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '信件ID',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`owner_id` int(11) DEFAULT NULL COMMENT '信件发送者(业主)ID',
`owner_name` varchar(50) DEFAULT NULL COMMENT '信件发送者(业主)名称',
`origin` char(1) DEFAULT '0' COMMENT '信件来源:0-信箱(默认),1-邮件,2-微信,3-公众号,4-app,5-pc',
`title` varchar(100) DEFAULT NULL COMMENT '信件标题',
`content` varchar(2000) DEFAULT NULL COMMENT '信箱内容',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
`status` char(1) DEFAULT '0' COMMENT '状态:0-未读(默认),1-已读',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='信件表';
DROP TABLE IF EXISTS `tb_owner`;
CREATE TABLE `tb_owner` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '业主ID',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区',
`house_id` int(11) DEFAULT NULL COMMENT '所属房产',
`name` varchar(50) DEFAULT NULL COMMENT '成员名称',
`picture` varchar(100) DEFAULT NULL COMMENT '成员照片',
`idcard` varchar(18) DEFAULT NULL COMMENT '身份证号',
`telephone` int(20) DEFAULT NULL COMMENT '联系方式',
`profession` varchar(20) DEFAULT NULL COMMENT '职业',
`sex` char(1) DEFAULT '0' COMMENT '性别:0-男(默认),1-女',
`type` char(1) DEFAULT '0' COMMENT '类型:0-房主(默认),1-租客',
`remark` varchar(200) DEFAULT '无' COMMENT '备注(默认无)',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
`birthday` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '出生日期',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='业主表';
DROP TABLE IF EXISTS `tb_parking`;
CREATE TABLE `tb_parking` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '车位ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`picture` varchar(100) DEFAULT NULL COMMENT '车位图片',
`code` varchar(20) DEFAULT NULL COMMENT '车位编号',
`name` varchar(50) DEFAULT NULL COMMENT '车位名称',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='车位表';
DROP TABLE IF EXISTS `tb_parking_use`;
CREATE TABLE `tb_parking_use` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '车位使用ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`code` varchar(20) DEFAULT NULL COMMENT '车位编号',
`car_number` varchar(20) DEFAULT NULL COMMENT '车牌号码',
`picture` varchar(100) DEFAULT NULL COMMENT '车辆牌照(照片)',
`owner_name` varchar(50) DEFAULT NULL COMMENT '车辆所有人(业主)名称',
`owner_id` int(11) DEFAULT NULL COMMENT '车辆所有人(业主)ID',
`telephone` int(20) DEFAULT NULL COMMENT '联系方式',
`use_type` char(1) DEFAULT '0' COMMENT '使用性质:0-购买(默认),1-月租,2-年租',
`total_fee` int(11) DEFAULT NULL COMMENT '总费用(¥),以分为单位',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
`start_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '(使用)开始时间',
`end_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '(使用)结束时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='车位使用表';
DROP TABLE IF EXISTS `tb_pet`;
CREATE TABLE `tb_pet` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '宠物ID',
`picture` varchar(100) DEFAULT NULL COMMENT '宠物照片',
`owner_name` varchar(50) DEFAULT NULL COMMENT '所属成员(业主)名称',
`owner_id` int(11) DEFAULT NULL COMMENT '所属成员(业主)ID',
`name` varchar(50) DEFAULT NULL COMMENT '宠物名称',
`color` varchar(10) DEFAULT NULL COMMENT '宠物颜色',
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
`adopt_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '收养时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='宠物表';
DROP TABLE IF EXISTS `tb_repair`;
CREATE TABLE `tb_repair` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '维修ID',
`community_name` varchar(50) DEFAULT NULL COMMENT '所属小区名称',
`community_id` int(11) DEFAULT NULL COMMENT '所属小区ID',
`building_name` varchar(50) DEFAULT NULL COMMENT '所属楼栋名称',
`building_id` int(11) DEFAULT NULL COMMENT '所属楼栋ID',
`owner_name` varchar(50) DEFAULT NULL COMMENT '报修人员(业主)名称',
`owner_id` int(11) DEFAULT NULL COMMENT '报修人员(业主)ID',
`device_name` varchar(50) DEFAULT NULL COMMENT '设备名称',
`device_id` int(11) DEFAULT NULL COMMENT '设备编号ID',
`description` varchar(500) DEFAULT NULL COMMENT '报修描述',
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '更新时间',
`status` char(1) DEFAULT '0' COMMENT '状态:0-待受理,1-已受理,2-修理完毕',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='维修表';
2.导入依赖
在pom.xml中写入
<dependencies>
<!--web项目-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--mybatis持久层-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
<!--通用mapper起步依赖-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.0.4</version>
</dependency>
<!--MySQL数据库驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--mybatis分页插件-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.3</version>
</dependency>
<!--文件上传相关依赖-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!--JSON格式化工具包FastJSON-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.28</version>
</dependency>
<!--junit测试-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<!--配置文件运行支持-->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.html</include>
</includes>
</resource>
</resources>
</build>
3.创建必要的包
4.根据数据库表创建实体类
以 Community 类为例
/*与数据库表进行关联*/
@Table(name = "tb_community")
/*实现序列化,为了在不同时间或不同平台的JVM之间共享实例对象*/
public class Community implements Serializable {
@Id //声明主键
private Integer id;
private String code;
private String name;
private String address;
private double area;
private Integer totalBuildings;
private Integer totalHouseholds;
private Integer greeningRate;
private String thumbnail;
private String developer;
private String estateCompany;
private Date createTime;
private Date updateTime;
private String status;
public Community() { }
public Community(Integer id, String code, String name, String address, double area, Integer totalBuildings, Integer totalHouseholds, Integer greeningRate, String thumbnail, String developer, String estateCompany, Date createTime, Date updateTime, String status) {
this.id = id;
this.code = code;
this.name = name;
this.address = address;
this.area = area;
this.totalBuildings = totalBuildings;
this.totalHouseholds = totalHouseholds;
this.greeningRate = greeningRate;
this.thumbnail = thumbnail;
this.developer = developer;
this.estateCompany = estateCompany;
this.createTime = createTime;
this.updateTime = updateTime;
this.status = status;
}
public Integer getId() { return id; }
public void setId(Integer id) { this.id = id; }
public String getCode() { return code; }
public void setCode(String code) { this.code = code; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getAddress() { return address; }
public void setAddress(String address) { this.address = address; }
public double getArea() { return area; }
public void setArea(double area) { this.area = area; }
public Integer getTotalBuildings() { return totalBuildings; }
public void setTotalBuildings(Integer totalBuildings) { this.totalBuildings = totalBuildings; }
public Integer getTotalHouseholds() { return totalHouseholds; }
public void setTotalHouseholds(Integer totalHouseholds) { this.totalHouseholds = totalHouseholds; }
public Integer getGreeningRate() { return greeningRate; }
public void setGreeningRate(Integer greeningRate) { this.greeningRate = greeningRate; }
public String getThumbnail() { return thumbnail; }
public void setThumbnail(String thumbnail) { this.thumbnail = thumbnail; }
public String getDeveloper() { return developer; }
public void setDeveloper(String developer) { this.developer = developer; }
public String getEstateCompany() { return estateCompany; }
public void setEstateCompany(String estateCompany) { this.estateCompany = estateCompany; }
public Date getCreateTime() { return createTime; }
public void setCreateTime(Date createTime) { this.createTime = createTime; }
public Date getUpdateTime() { return updateTime; }
public void setUpdateTime(Date updateTime) { this.updateTime = updateTime; }
public String getStatus() { return status; }
public void setStatus(String status) { this.status = status; }
@Override
public String toString() {
return "Community{" +
"id=" + id +
", code='" + code + '\'' +
", name='" + name + '\'' +
", address='" + address + '\'' +
", area=" + area +
", totalBuildings=" + totalBuildings +
", totalHouseholds=" + totalHouseholds +
", greeningRate=" + greeningRate +
", thumbnail='" + thumbnail + '\'' +
", developer='" + developer + '\'' +
", estateCompany='" + estateCompany + '\'' +
", createTime=" + createTime +
", updateTime=" + updateTime +
", status='" + status + '\'' +
'}';
}
}
4.编写 Mapper 及其配置文件
以 CommunityMapper 为例
(1) 写法一:【手写Mapper方法 + 手写配置文件】 (不推荐)
//声明Mapper
@Repository
/*继承Mapper的泛型,指向Community实体类,会提供一些常用的默认方法*/
public interface CommunityMapper extends Mapper<Community> {
//添加社区
public int insertCommunity(Community community);
//根据【社区id】删除社区
public int updateCommunityById(int communityId);
//根据【社区id】更新社区信息
public int deleteCommunity(int communityId);
//根据【社区id】查询社区
public Community queryCommunity(int communityId);
//查询所有社区
public List<Community> queryAllCommunity();
}
Mapper.xml文件
...
(2) 写法二:用【Mapper泛型】 (使用 Mapper泛型可节省 Mapper.xml 配置文件)
//声明Mapper
@Repository
/*继承Mapper的泛型,指向Community实体类,会提供一些常用的默认方法*/
public interface CommunityMapper extends Mapper<Community> { }
(3) 写法三:用【mybatis反向生成工具】
(使用mybatis反向生成工具可根据数据库自动生成【所有mapper层】及【pojo层】的【类或配置文件】)
见:https://blog.csdn.net/weixin_42431775/article/details/123636658 中 SpringBoot整合【mybatis】框架 的内容
5.编写 service
以 CommunityService、CommunityServiceImpl 的简单功能为例
//CommunityService
public interface CommunityService {
//获取全部数据
public List<Community> findAllCommunity();
}
//CommunityServiceImpl
@Service
public class CommunityServiceImpl implements CommunityService {
@Resource
private CommunityMapper mapper;
@Override
public List<Community> findAllCommunity() {
List<Community> communityList = mapper.selectAll();
return communityList;
}
}
6.编写 controller
以 CommunityController 为例
/*community管理控制层*/
@RestController
@RequestMapping("/community")
public class CommunityController {
@Resource
private CommunityService service;
@RequestMapping("findAllCommunity")
public List<Community> findAllCommunity(){
List<Community> communityList = service.findAllCommunity();
return communityList;
}
}
7.访问
通过 http://localhost:8080/community/findAllCommunity 查看初步结果