@Entity
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
如果model無法自動取得, 需在spring導入程式加上annotation提示系統自動載入, 若model在主module下則無須此動作
@EntityScan("testing.spring.model")
^^^^^^^^^^^^^ model 的package位置
one side set to map by join column and inverse join column
@ManyToMany
@JoinTable(name="A_B",joinColumns= @JoinColumn(name="B_id"), inverseJoinColumns=@JoinColumn(name = "A_id"))
another side set to map by variable name
@ManyToMany(mappedBy = "As")
repository --> add standard spring CRUD function
public interface xxxRepository extends CrudRepository<type of data model, type of id>{
}
H2資料庫來源自動設定 add at application.properties
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=
留言列表