課程
/后端開發
/Java
/2小時學會Spring Boot
只能傳個Example對象作參數 而且返回值是optional類型的 怎么回事啊
2018-01-28
源自:2小時學會Spring Boot 5-2
正在回答
//通過id查詢女生的方法 @GetMapping(value?=?"/girls/{id}") public?Girl?getGirl(@PathVariable("id")?Integer?id?){ ????return?girlRepository.findOne(id); } //定義的接口 public?interface?GirlRepository?extends?JpaRepository<Girl,Integer>?{ ????//通過年齡來查詢 ????public?List<Girl>?findByAge(Integer?age); } findOne方法應該是默認使用注入的bean的主鍵來查詢,可以看一下實體類那個@id是不是加上了,下面是我的bean package?com.imooc.demo.bean; import?javax.persistence.Entity; import?javax.persistence.GeneratedValue; import?javax.persistence.Id; @Entity public?class?Girl?{ ????@Id ????@GeneratedValue ????private?Integer?id; ????private?String?cupSize; ????private?Integer?age; ????public?Girl(){ ????} ????public?Integer?getId()?{ ????????return?id; ????} ????public?void?setId(Integer?id)?{ ????????this.id?=?id; ????} ????public?String?getCupSize()?{ ????????return?cupSize; ????} ????public?void?setCupSize(String?cupSize)?{ ????????this.cupSize?=?cupSize; ????} ????public?Integer?getAge()?{ ????????return?age; ????} ????public?void?setAge(Integer?age)?{ ????????this.age?=?age; ????} }
fenkapian 提問者
風過淚落雪飄 回復 fenkapian 提問者
fenkapian 提問者 回復 風過淚落雪飄
慕娘9428916 回復 fenkapian 提問者
煮茶溫書 回復 慕娘9428916
ali是個小太陽 回復 fenkapian 提問者
emmm 我是改了 pom.xml 里的?
<parent> ????<groupId>org.springframework.boot</groupId> ????<artifactId>spring-boot-starter-parent</artifactId> ????<version>1.5.9.RELEASE</version> ????<relativePath/>? </parent>
的版本? ?好像?2.0.2.RELEASE? 就是不行 不知道求大佬指點
客氣啦
舉報
Spring Boot入門視頻教程,你將學會使用Spring Boot快速構建應用程序
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2018-01-30
2018-06-08
emmm 我是改了 pom.xml 里的?
的版本? ?好像?2.0.2.RELEASE? 就是不行 不知道求大佬指點
2018-01-31
客氣啦