第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用Spring Boot為傳記后端制作實(shí)體類和控制器?

如何使用Spring Boot為傳記后端制作實(shí)體類和控制器?

慕森王 2023-09-20 16:21:11
如何為傳記頁面(在網(wǎng)站上)的后端部分創(chuàng)建一個(gè)實(shí)體類。我不確定如何處理這樣的事情,因?yàn)闆]有需要從服務(wù)器發(fā)送的特定內(nèi)容。我附上了一些用于實(shí)體類的代碼。我的實(shí)體類似乎是使用 Spring Boot 在網(wǎng)站上為傳記頁面創(chuàng)建后端的正確方法嗎?實(shí)體類    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 回答

?
不負(fù)相思意

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊

您可以執(zhí)行以下操作來實(shí)現(xiàn)一個(gè)處理對(duì) Biography 實(shí)體的請(qǐng)求的 Spring 控制器。

  1. 您的傳記實(shí)體似乎不錯(cuò)

  2. 要使用它,您可以利用org.springframework.data.repository.CrudRepository;
    即:

public interface BiographyRepository  extends CrudRepository <Biography, Long> {

}
  1. 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...

}

根據(jù)您的需要,更好的做法可能是通過@Service控制器中的存儲(chǔ)庫進(jìn)行操作。


查看完整回答
反對(duì) 回復(fù) 2023-09-20
  • 1 回答
  • 0 關(guān)注
  • 84 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)