第二天

团队项目:
完成了星级评估管理部分的后端和前端的代码编写和连接,但还无法在前端显示。 有报错。
完成了安全风险部分基础的增删改查,尚未添加具体的业务逻辑,vue前端尚刚刚开始学习,预计完成安全风险管理基础的增删改查还需要3小时。
完成了安全检查部分前端的vue代码。

最开始,写的代码出现问题是后端可以用,前端可以接受到后端传来的数据,但是无法在表格上显示。
部分代码:
package com.example.demo.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import java.util.Date;

@Entity(name = "safetyrisk")
public class SafetyRisk {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String risk_code;
private String department;
private String professional_system;
private String risk_category;
private String risk_item;
private String risk_point;
private String risk_level;
private String harm_degree;
private String control_measures;
private String control_position;
private String control_personnel;
private String quantified_requirements;
private Date entry_start_date;
private Date entry_end_date;
private String review_status;
private Date review_date;

// Getters and Setters
public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

public String getRisk_code() {
    return risk_code;
}

public void setRisk_code(String risk_code) {
    this.risk_code = risk_code;
}

public String getDepartment() {
    return department;
}

public void setDepartment(String department) {
    this.department = department;
}

public String getProfessional_system() {
    return professional_system;
}

public void setProfessional_system(String professional_system) {
    this.professional_system = professional_system;
}

public String getRisk_category() {
    return risk_category;
}

public void setRisk_category(String risk_category) {
    this.risk_category = risk_category;
}

public String getRisk_item() {
    return risk_item;
}

public void setRisk_item(String risk_item) {
    this.risk_item = risk_item;
}

public String getRisk_point() {
    return risk_point;
}

public void setRisk_point(String risk_point) {
    this.risk_point = risk_point;
}

public String getRisk_level() {
    return risk_level;
}

public void setRisk_level(String risk_level) {
    this.risk_level = risk_level;
}

public String getHarm_degree() {
    return harm_degree;
}

public void setHarm_degree(String harm_degree) {
    this.harm_degree = harm_degree;
}

public String getControl_measures() {
    return control_measures;
}

public void setControl_measures(String control_measures) {
    this.control_measures = control_measures;
}

public String getControl_position() {
    return control_position;
}

public void setControl_position(String control_position) {
    this.control_position = control_position;
}

public String getControl_personnel() {
    return control_personnel;
}

public void setControl_personnel(String control_personnel) {
    this.control_personnel = control_personnel;
}

public String getQuantified_requirements() {
    return quantified_requirements;
}

public void setQuantified_requirements(String quantified_requirements) {
    this.quantified_requirements = quantified_requirements;
}

public Date getEntry_start_date() {
    return entry_start_date;
}

public void setEntry_start_date(Date entry_start_date) {
    this.entry_start_date = entry_start_date;
}

public Date getEntry_end_date() {
    return entry_end_date;
}

public void setEntry_end_date(Date entry_end_date) {
    this.entry_end_date = entry_end_date;
}

public String getReview_status() {
    return review_status;
}

public void setReview_status(String review_status) {
    this.review_status = review_status;
}

public Date getReview_date() {
    return review_date;
}

public void setReview_date(Date review_date) {
    this.review_date = review_date;
}

}
package com.example.demo.repository;

import com.example.demo.entity.SafetyRisk;
import org.springframework.data.jpa.repository.JpaRepository;

public interface SafetyRiskRepository extends JpaRepository<SafetyRisk, Integer> {
}
package com.example.demo.controller;

import com.example.demo.entity.SafetyRisk;
import com.example.demo.repository.SafetyRiskRepository;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Controller
public class SafetyRiskController {

@Autowired
private SafetyRiskRepository safetyRiskRepository;
@Autowired
private ObjectMapper objectMapper; // 注入 ObjectMapper

@GetMapping("/safety-risk-report")
public String showSafetyRiskReport(Model model) {
    List<SafetyRisk> safetyRisks = safetyRiskRepository.findAll();
    // 添加日志输出
    System.out.println("safetyRisks 是否为 null: " + (safetyRisks == null));
    System.out.println("safetyRisks 大小: " + (safetyRisks != null ? safetyRisks.size() : 0));
    try {
        String safetyRisksJson = objectMapper.writeValueAsString(safetyRisks);
        model.addAttribute("safetyRisksJson", safetyRisksJson); // 传递 JSON 字符串
    } catch (Exception e) {
        e.printStackTrace();
    }
    model.addAttribute("safetyRisks", safetyRisks);
    return "safety-risk-report";
}

}

posted @ 2025-04-17 00:04  深度检测  阅读(13)  评论(0)    收藏  举报