// 后端代码示例(Spring Boot)
@RestController
@RequestMapping("/student")
public class StudentController {
@Autowired
private StudentService studentService;
@GetMapping("/{id}")
public ResponseEntity
return ResponseEntity.ok(studentService.findById(id));
}
@PostMapping("/")
public ResponseEntity
studentService.addStudent(student);
return ResponseEntity.status(HttpStatus.CREATED).build();
}
}
// 前端代码示例(Vue.js)
学生信息管理
export default {
data() {
return {
newStudent: { name: '', age: null }
};
},
methods: {
async addStudent() {
await fetch('http://localhost:8080/student', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(this.newStudent)
});
this.newStudent = { name: '', age: null };
}
}
};
]]>
本站知识库部分内容及素材来源于互联网,如有侵权,联系必删!