如何為傳記頁面(在網站上)的后端部分創建一個實體類。我不確定如何處理這樣的事情,因為沒有需要從服務器發送的特定內容。我附上了一些用于實體類的代碼。我的實體類似乎是使用 Spring Boot 在網站上為傳記頁面創建后端的正確方法嗎?實體類 import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name="BIOGRAPHY") public class Biography { @Id @GeneratedValue private Long sectionId; @Column(name = "section_title") private String titleSection; @Column(name = "section_text") private String textSection; public Long getSectionId() { return sectionId; } public String getTitleSection() { return titleSection; } public String getTextSection() { return textSection; } @Override public String toString() { return "EmployeeEntity [sectionId=" + sectionId + ", titleSection=" + titleSection + ", textSection=" + textSection + "]"; } }
1 回答

不負相思意
TA貢獻1777條經驗 獲得超10個贊
您可以執行以下操作來實現一個處理對 Biography 實體的請求的 Spring 控制器。
您的傳記實體似乎不錯
要使用它,您可以利用
org.springframework.data.repository.CrudRepository;
即:
public interface BiographyRepository extends CrudRepository <Biography, Long> { }
Spring 非常靈活,您可以按照自己喜歡的方式組織代碼。以下是如何組織控制器代碼的示例:
@RestController
@RequestMapping
public class BiographyController {
@Autowired
private BiographyRepository biographyRepository;
@RequestMapping(value = "/biography, method = RequestMethod.POST)
public @ResponseBody
Response create (HttpServletRequest request) {
//read biography object from the request
biographyRepository.save(biography);
}
//other methods...
}
根據您的需要,更好的做法可能是通過@Service控制器中的存儲庫進行操作。
添加回答
舉報
0/150
提交
取消