为什么我的findOne方法不能传id当参数
只能传个Example对象作参数 而且返回值是optional类型的 怎么回事啊
只能传个Example对象作参数 而且返回值是optional类型的 怎么回事啊
2018-01-28
//通过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;
}
}举报