以下是基于SpringBoot + MyBatis的相关SQL和Java代码:
1. 创建抄表区间表
```sql
CREATE TABLE meter_reading_interval (
id INT(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
type VARCHAR(50) NOT NULL COMMENT '抄表种类',
specification VARCHAR(50) NOT NULL COMMENT '抄表规格',
cycle INT(11) NOT NULL COMMENT '抄表周期(天)',
start_time DATETIME NOT NULL COMMENT '开始时间',
end_time DATETIME NOT NULL COMMENT '结束时间',
PRIMARY KEY (id)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COMMENT='抄表区间表';
```
2. 定义MeterReadingInterval实体类
```java
public class MeterReadingInterval {
private Integer id;
private String type;
private String specification;
private Integer cycle;
private Date startTime;
private Date endTime;
// getter and setter methods
}
```
3. 创建Mapper接口
```java
@Mapper
public interface MeterReadingIntervalMapper {
@Select("SELECT * FROM meter_reading_interval WHERE id = #{id}")
MeterReadingInterval findById(Integer id);
@Insert("INSERT INTO meter_reading_interval(type, specification, cycle, start_time, end_time) " +
"VALUES(#{type}, #{specification}, #{cycle}, #{startTime}, #{endTime})")
int insert(MeterReadingInterval meterReadingInterval);
@Update("UPDATE meter_reading_interval SET type=#{type}, specification=#{specification}, cycle=#{cycle}, " +
"start_time=#{startTime}, end_time=#{endTime} WHERE id=#{id}")
int update(MeterReadingInterval meterReadingInterval);
@Delete("DELETE FROM meter_reading_interval WHERE id=#{id}")
int delete(Integer id);
}
```
4. 创建Service层
```java
@Service
public class MeterReadingIntervalService {
@Autowired
private MeterReadingIntervalMapper meterReadingIntervalMapper;
public MeterReadingInterval findById(Integer id) {
return meterReadingIntervalMapper.findById(id);
}
public int insert(MeterReadingInterval meterReadingInterval) {
return meterReadingIntervalMapper.insert(meterReadingInterval);
}
public int update(MeterReadingInterval meterReadingInterval) {
return meterReadingIntervalMapper.update(meterReadingInterval);
}