您如何为传记页面(在网站上)的后端部分创建实体类。我不确定如何处理这样的事情,因为不需要从服务器发送特定的东西。我已经附加了一些用于实体类的代码。
我的实体类似乎是使用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 + "]";
}
}
答案 0 :(得分:1)
在这里您可以实现一个Spring控制器,该控制器负责处理对Biography实体的请求。
org.springframework.data.repository.CrudRepository;
public interface BiographyRepository extends CrudRepository <Biography, Long> {
}
@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...
}
根据您的需求,更好的做法是通过Controller中的@Service
使用存储库。
希望有帮助。