基于springboot+vue的师生健康信息管理系统(前后端分离)
该系统的具体实现涉及到前后端的开发,以下是一些关键的代码和配置示例。
后端(Spring Boot):
- 实体类
HealthInfo.java
:
@Entity
public class HealthInfo {
@Id
private Long id;
private String studentId;
private String temperature;
private String healthStatus;
// 省略getter和setter
}
- Repository接口
HealthInfoRepository.java
:
public interface HealthInfoRepository extends JpaRepository<HealthInfo, Long> {
List<HealthInfo> findByStudentId(String studentId);
}
- Service接口
HealthInfoService.java
和实现类:
public interface HealthInfoService {
HealthInfo saveHealthInfo(HealthInfo healthInfo);
List<HealthInfo> findAll();
List<HealthInfo> findByStudentId(String studentId);
}
@Service
public class HealthInfoServiceImpl implements HealthInfoService {
@Autowired
private HealthInfoRepository healthInfoRepository;
@Override
public HealthInfo saveHealthInfo(HealthInfo healthInfo) {
return healthInfoRepository.save(healthInfo);
}
@Override
public List<HealthInfo> findAll() {
return healthInfoRepository.findAll();
}
@Override
public List<HealthInfo> findByStudentId(String studentId) {
return healthInfoRepository.findByStudentId(studentId);
}
}
- Controller
HealthInfoController.java
:
@RestController
@RequestMapping("/api/healthinfo")
public class HealthInfoController {
@Autowired
private HealthInfoService healthInfoService;
@PostMapping
public HealthInfo saveHealthInfo(@RequestBody HealthInfo healthInfo) {
return healthInfoService.saveHealthInfo(healthInfo);
}
@GetMapping
public List<HealthInfo> getAllHealthInfo() {
return healthInfoService.findAll();
}
@GetMapping("/student/{studentId}")
public List<HealthInfo> getHealthInfoByStudentId(@PathVariable String studentId) {
return healthInfoService.findByStudentId(studentId);
}
}
前端(Vue.js):
- 安装axios进行HTTP请求:
npm install axios
- Vue组件中发送请求和处理数据:
<template>
<div>
<!-- 省略界面代码 -->
</div>
</template>
<script>
import axios from 'axios';
export default {
data() {
return {
healthInfoList: []
};
},
created() {
this.fetchHealthInfo();
},
methods: {
async fetchHealthInfo() {
try {
const response = await axios.get('/api/healthinfo');
this.healthInfo
评论已关闭