SpringData之webSupport

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>{
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章