1.配置
@Configuration
@EnableWebMvc
@EnableSpringDataWebSupport
class WebConfiguration {
}
2.controller
@RequestMapping("/{id}")
TestPerson showUserForm(@PathVariable("id") TestPerson user) {
//參數實體TestPerson必須使用@Entity標識的實體類
//會自動根據傳參的ID自動調用findById方法查詢
return user;
}
此時,repository必須繼承 CrudRepository
public interface MyRepository extends CrudRepository<TestPerson,Integer>{
}