Pri*_*mal 3 java spring spring-mvc spring-data spring-boot
即时通讯到本springboot教程,我spring data在我的项目中使用,我试图添加data to database..当我试图这样做时使用以下bt我得到一个错误说
调用方法public abstract java.lang.Object org.springframework.data.repository.CrudRepository.save(java.lang.Object)是无访问器方法!
这是我的代码,
//my controller
@RequestMapping("/mode")
public String showProducts(ModeRepository repository){
Mode m = new Mode();
m.setSeats(2);
repository.save(m); //this is where the error getting from
return "product";
}
//implementing crud with mode repository
@Repository
public interface ModeRepository extends CrudRepository<Mode, Long> {
}
//my mode class
@Entity
@Table(name="mode")
public class Mode implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(unique=true, nullable=false)
private int idMode;
@Column(nullable=false)
private int seats;
//assume that there are getters and setters
}
Run Code Online (Sandbox Code Playgroud)
我是新手,springboot有人可以告诉我我做错了什么,感谢有人能给我一个链接来了解springdata
其他的spring documentation
WeM*_*are 12
更改控制器代码,以便ModeRepository是私有自动装配字段.
@Autowired //don't forget the setter
private ModeRepository repository;
@RequestMapping("/mode")
public String showProducts(){
Mode m = new Mode();
m.setSeats(2);
repository.save(m); //this is where the error getting from
return "product";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5520 次 |
| 最近记录: |