我在Spring Boot中有一个错误
moduleContraller
@RestController
@RequestMapping("/module")
@Validated
public class ModuleController {
private Logger log = LoggerFactory.getLogger(this.getClass());
private final ModuleService moduleService;
private final ResultGenerator generator;
@Autowired
public ModuleController(ModuleService moduleService, ResultGenerator generator) {
this.moduleService = moduleService;
this.generator = generator;
}
@PostMapping("/add")
public RestResult addModule(@Valid Module module){
return generator.getSuccessResult("添加模块成功", moduleService.saveModule(module));
}
@GetMapping("/all")
public RestResult getModule(){
return generator.getSuccessResult("查找成功", moduleService.getModule());
}
@GetMapping("/{id}")
public RestResult getModuleByMID(@PathVariable("id") Integer MID){
return generator.getSuccessResult("查找成功", moduleService.getModuleByMID(MID));
}
@PutMapping("/edit/{id}")
public RestResult editModule(@PathVariable("id") Integer MID, String title, String description){
return generator.getSuccessResult("修改成功", moduleService.editModule(MID, title, description));
}
@DeleteMapping("/remove/{id}")
public void removeModule(@PathVariable("id")Integer MID) {
moduleService.removeModuleByID(MID);
}
}
模块存储库
package org.tyrik.toys.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.tyrik.toys.entity.Module;
@Repository
public interface ModuleRepository extends JpaRepository<Module, Integer> {
}
还有这里的ModuleService
/**
* 模块接口
*/
public interface ModuleService {
Module saveModule(Module module);
List<Module> getModule();
Optional<Module> getModuleByMID(Integer MID);
Module editModule(Integer MID, String title, String description);
void removeModuleByID(Integer MID);
}
现在我睡不着。这个问题困扰了我整整一整天,希望你们能帮助我解决这个问题。
凤凰求蛊
相关分类