|
|
package com.yanzhen.service; // 定义包名
|
|
|
|
|
|
import com.yanzhen.mapper.RecordMapper; // 导入RecordMapper接口
|
|
|
import com.yanzhen.entity.Record; // 导入Record实体类
|
|
|
import com.github.pagehelper.PageHelper; // 导入PageHelper分页工具类
|
|
|
import com.github.pagehelper.PageInfo; // 导入PageInfo分页信息类
|
|
|
import org.springframework.beans.factory.annotation.Autowired; // 导入Spring的自动装配注解
|
|
|
import org.springframework.stereotype.Service; // 导入Spring的服务层注解
|
|
|
import org.springframework.util.StringUtils; // 导入Spring的工具类,用于字符串操作
|
|
|
|
|
|
@Service // 标注该类为服务层组件
|
|
|
public class RecordService用户id的增删查改数据库 { // 定义RecordService类 “----管理员/宿管”
|
|
|
|
|
|
@Autowired // 自动装配RecordMapper对象
|
|
|
private RecordMapper recordMapper;
|
|
|
|
|
|
public int create(Record record) { // 创建记录的方法
|
|
|
return recordMapper.create(record); // 调用Mapper层的create方法
|
|
|
}
|
|
|
|
|
|
public int delete(String ids) { // 根据ID字符串批量删除记录的方法
|
|
|
String[] arr = ids.split(","); // 将ID字符串按逗号分割成数组
|
|
|
int row = 0; // 初始化受影响行数为0
|
|
|
for (String s : arr) { // 遍历ID数组
|
|
|
if(!StringUtils.isEmpty(s)){ // 如果ID不为空
|
|
|
recordMapper.delete(Integer.parseInt(s)); // 调用Mapper层的delete方法删除记录
|
|
|
row++; // 受影响行数加1
|
|
|
}
|
|
|
}
|
|
|
return row; // 返回受影响行数
|
|
|
}
|
|
|
|
|
|
public int delete(Integer id) { // 根据ID删除记录的方法
|
|
|
return recordMapper.delete(id); // 调用Mapper层的delete方法
|
|
|
}
|
|
|
|
|
|
public int update(Record record) { // 更新记录的方法
|
|
|
return recordMapper.update(record); // 调用Mapper层的update方法
|
|
|
}
|
|
|
|
|
|
public int updateSelective(Record record) { // 选择性更新记录的方法
|
|
|
return recordMapper.updateSelective(record); // 调用Mapper层的updateSelective方法
|
|
|
}
|
|
|
|
|
|
public PageInfo<Record> query(Record record) { // 查询记录列表的方法
|
|
|
if(record != null && record.getPage() != null){ // 如果查询条件和分页信息不为空
|
|
|
PageHelper.startPage(record.getPage(),record.getLimit()); // 启动分页并设置分页参数
|
|
|
}
|
|
|
return new PageInfo<Record>(recordMapper.query(record)); // 调用Mapper层的query方法并封装成PageInfo对象返回
|
|
|
}
|
|
|
|
|
|
public Record detail(Integer id) { // 根据ID获取详情的方法
|
|
|
return recordMapper.detail(id); // 调用Mapper层的detail方法
|
|
|
}
|
|
|
|
|
|
public int count(Record record) { // 统计记录数量的方法
|
|
|
return recordMapper.count(record); // 调用Mapper层的count方法
|
|
|
}
|
|
|
} |