使用save保存游离态对象获取其id

我使用的数据库是mysql,

1,在entity类的id处添加注解

    

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

 2,在数据库建表时,写上auto_increment

  

CREATE TABLE  t_user 
(
	id  int auto_increment primary key,

自己试了试1和2缺一不可,

猜你喜欢

转载自yk1129013140.iteye.com/blog/2228604
今日推荐