You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.3 KiB
76 lines
2.3 KiB
package com.yanzhen.controller; // 定义包名
|
|
|
|
import com.github.pagehelper.PageInfo; // 导入分页插件
|
|
import com.yanzhen.entity.Record; // 导入记录实体类
|
|
import com.yanzhen.service.RecordService; // 导入记录服务接口
|
|
import com.yanzhen.utils.Result; // 导入结果工具类
|
|
import org.springframework.beans.factory.annotation.Autowired; // 导入自动装配注解
|
|
import org.springframework.web.bind.annotation.*; // 导入Spring MVC相关注解
|
|
|
|
import java.util.Map; // 导入Map接口
|
|
//记录管理的控制器
|
|
@RestController
|
|
@RequestMapping("/record")
|
|
public class RecordController {
|
|
//注入实例
|
|
//注入记录服务类
|
|
@Autowired
|
|
private RecordService recordService;
|
|
//创建新的实例
|
|
@PostMapping("create")
|
|
public Result create(@RequestBody Record record){
|
|
//在记录管理服务类中引用create方法
|
|
int flag = recordService.create(record);
|
|
//判断是否创建成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//删除记录管理信息
|
|
@GetMapping("delete")
|
|
public Result delete(String ids){
|
|
//在记录管理服务类中引用delete方法
|
|
int flag = recordService.delete(ids);
|
|
//判断是否删除成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//更新记录管理信息
|
|
@PostMapping("update")
|
|
public Result update(@RequestBody Record record){
|
|
//在记录管理服务类中引用update方法
|
|
int flag = recordService.update(record);
|
|
//判断是否更新成功
|
|
if(flag>0){
|
|
//成功
|
|
return Result.ok();
|
|
}else{
|
|
//失败
|
|
return Result.fail();
|
|
}
|
|
}
|
|
//获取记录详细信息
|
|
@GetMapping("detail")
|
|
public Record detail(Integer id){
|
|
//返回结果
|
|
return recordService.detail(id);
|
|
}
|
|
//查询记录管理信息
|
|
@PostMapping("query")
|
|
public Map<String,Object> query(@RequestBody Record record){
|
|
//创建分页对象
|
|
PageInfo<Record> pageInfo = recordService.query(record);
|
|
//返回结果
|
|
return Result.ok(pageInfo);
|
|
}
|
|
|
|
} |