Merge remote-tracking branch 'origin/backed-new' into backed-new
This commit is contained in:
commit
2249f74b9a
|
@ -10,14 +10,9 @@ public class WebLoginConfig implements WebMvcConfigurer {
|
|||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
// 对所有路径应用此规则
|
||||
.allowedOrigins("http://localhost:3000")
|
||||
// 允许来自这个源的请求
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
// 允许的HTTP方法
|
||||
.allowedHeaders("Authorization", "*")
|
||||
// 允许的请求头
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true);
|
||||
// 允许发送Cookie
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package edu.zrh.healthsystem.controller;
|
||||
|
||||
import edu.zrh.healthsystem.entity.Template; // 假设你有一个Template实体类
|
||||
import edu.zrh.healthsystem.service.TemplateService; // 假设你有一个TemplateService类
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/templates")
|
||||
public class TemplateController {
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<Template> createTemplate(@RequestBody Template template) {
|
||||
Template savedTemplate = templateService.createTemplate(template);
|
||||
return ResponseEntity.ok(savedTemplate);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Template>> getAllTemplates(@RequestParam(required = false) String templateName,
|
||||
@RequestParam(required = false) String department) {
|
||||
List<Template> templates = templateService.getAllTemplates(templateName, department);
|
||||
return ResponseEntity.ok(templates);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Template> updateTemplate(@PathVariable Long id, @RequestBody Template template) {
|
||||
Template updatedTemplate = templateService.updateTemplate(id, template);
|
||||
return ResponseEntity.ok(updatedTemplate);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteTemplate(@PathVariable Long id) {
|
||||
templateService.deleteTemplate(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
// 其他API端点...
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package edu.zrh.healthsystem.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Table(name = "templates")
|
||||
@Data
|
||||
public class Template {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String templateName;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String department;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String type;
|
||||
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String content;
|
||||
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String remarks;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package edu.zrh.healthsystem.repository;
|
||||
|
||||
import edu.zrh.healthsystem.entity.Template; // 假设你有一个Template实体类
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface TemplateRepository extends JpaRepository<Template, Long> {
|
||||
List<Template> findByTemplateNameContaining(String templateName);
|
||||
List<Template> findByDepartment(String department);
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package edu.zrh.healthsystem.service;
|
||||
|
||||
import edu.zrh.healthsystem.entity.Template; // 假设你有一个Template实体类
|
||||
import edu.zrh.healthsystem.repository.TemplateRepository; // 假设你有一个TemplateRepository接口
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class TemplateService {
|
||||
|
||||
@Autowired
|
||||
private TemplateRepository templateRepository;
|
||||
|
||||
public Template createTemplate(Template template) {
|
||||
return templateRepository.save(template);
|
||||
}
|
||||
|
||||
public Template updateTemplate(Long id, Template template) {
|
||||
template.setId(id); // 确保 ID 被设置
|
||||
return templateRepository.save(template);
|
||||
}
|
||||
|
||||
public void deleteTemplate(Long id) {
|
||||
templateRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public List<Template> getAllTemplates(String templateName, String department) {
|
||||
if (templateName != null && !templateName.isEmpty()) {
|
||||
return templateRepository.findByTemplateNameContaining(templateName);
|
||||
}
|
||||
if (department != null && !department.isEmpty()) {
|
||||
return templateRepository.findByDepartment(department);
|
||||
}
|
||||
return templateRepository.findAll();
|
||||
}
|
||||
|
||||
// 其他服务方法...
|
||||
}
|
Loading…
Reference in New Issue