Spring Data Rest暴露主键配置方法

下面的代码通过exposeIdsFor函数暴露了实体类的主键。

@Configuration
class RestMvcConfiguration{

    @Bean
    public RepositoryRestConfigurer repositoryRestConfigurer() {

        return new RepositoryRestConfigurerAdapter() {
            @Override
            public void configureRepositoryRestConfiguration(
                    RepositoryRestConfiguration config) {
                config
                        .exposeIdsFor(CompositeCase.class)
                        .exposeIdsFor(ExperimentAnswer.class)
                        .exposeIdsFor(Classes.class)
                        .exposeIdsFor(Exercise.class)
                        .exposeIdsFor(ExerciseAnswer.class)
                        .exposeIdsFor(Homework.class)
                        .exposeIdsFor(HomeworkAnswer.class)
                        .exposeIdsFor(Knowledge.class)
                        .exposeIdsFor(Problem.class)
                        .exposeIdsFor(Experiment.class)
                        .exposeIdsFor(Subject.class);

            }
        };
    }
}

标签: none

添加新评论