im reffering to this springboot
tutorial and im using spring data
in my project, im trying to add data to database
. using the following .
bt when im trying to do that i get an error saying
Invoked method public abstract java.lang.Object org.springframework.data.repository.CrudRepository.save(java.lang.Object) is no accessor method!
here is my code ,
//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
}
im new to springboot
and can someone tellme what am i doing wrong,
appreciate if someone could provide me a link to get to know about springdata
other than spring documentation
Change your controller code so that the ModeRepository is a private autowired field.
@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";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With