如果需要返回主键ID,可以通过自定义类继承RepositoryRestConfigurerAdapter
实现。如下:1
2
3
4
5
6
7
8
9
10
11
12
13import org.springframework.context.annotation.Configuration;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
import com.demo.entity.UserAccount;
public class RepositoryConfig extends RepositoryRestConfigurerAdapter {
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config) {
config.exposeIdsFor(UserAccount.class);
}
}
最终效果: