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

 

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