该查询请求的内容是一个完整的系统开发项目,涉及到后端开发和前端开发两个主要部分。以下是一个简化的后端Spring Boot框架的核心模块示例:
// 用户实体类
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String username;
private String password;
// 省略其他属性、getter和setter方法
}
// 舞蹈班级实体类
@Entity
public class Class {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String leader;
private String phone;
// 省略其他属性、getter和setter方法
}
// 舞蹈班级服务接口
public interface ClassService {
List<Class> findAll();
Class findById(Long id);
Class save(Class class);
void deleteById(Long id);
}
// 实现舞蹈班级服务
@Service
public class ClassServiceImpl implements ClassService {
@Autowired
private ClassRepository classRepository;
@Override
public List<Class> findAll() {
return classRepository.findAll();
}
@Override
public Class findById(Long id) {
return classRepository.findById(id).orElse(null);
}
@Override
public Class save(Class class) {
return classRepository.save(class);
}
@Override
public void deleteById(Long id) {
classRepository.deleteById(id);
}
}
// 控制器
@RestController
@RequestMapping("/api/v1/classes")
public class ClassController {
@Autowired
private ClassService classService;
@GetMapping
public ResponseEntity<List<Class>> getAllClasses() {
return ResponseEntity.ok(classService.findAll());
}
@GetMapping("/{id}")
public ResponseEntity<Class> getClassById(@PathVariable Long id) {
Class class = classService.findById(id);
if (class == null) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok(class);
}
@PostMapping
public ResponseEntity<Class> createClass(@RequestBody Class class) {
return ResponseEntity.ok(classService.save(class));
}
@PutMapping("/{id}")
public ResponseEntity<Class> updateClass(@PathVariable Long id, @RequestBody Class class) {
Class existingClass = classService.findById(id);
if (existingClass == null) {
return ResponseEntity.notFound().build();
}