我只是想揚鞭融入我春季啓動(JAX-RS)項目,Gradle.I內置了能夠產生泊塢窗(揚鞭UI)爲同一如下: 揚鞭2(春季狐狸)增加了「ES」我的API的
我都使用默認設置,配置我昂首闊步如下:
package com.abc;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@EnableAutoConfiguration
@SpringBootApplication
@EnableMongoRepositories
@Slf4j
@Import({springfox.documentation.spring.data.rest.configuration.SpringDataRestConfiguration.class,springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration.class})
@EnableSwagger2
public class ServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ServiceApplication.class, args);
}
public static void run(String[] args) throws Exception{
log.info("Started application on: 8080");
}
}
我們可以在圖像中看到GET活動API泊塢窗顯示/ eventses ..所以,從那裏還增加ES到/事件API,它可寫爲:
@GET
public HashMap<String, Object> getEventList(@DefaultValue("1") @QueryParam("page") int page,
@DefaultValue("10") @QueryParam("rpp") int rpp, @QueryParam("events") String eventIds) {
HashMap<String, Object> eventsResultMap= new HashMap<String, Object>();
List<Events> events = null;
if (eventIds != null && eventIds.length() > 0) {
List<String> eventsIdList = Arrays.asList(eventIds.split(","));
log.info("" + eventsIdList);
events = eventService.getEvents(eventsIdList);
} else {
events = eventService.getEvents(page - 1, rpp);
}
eventsResultMap.put("EVENTS", events);
HashMap<String, Object> recordsMetaMap = new HashMap<String, Object>();
recordsMetaMap.put("total", eventService.totalCount());
recordsMetaMap.put("page", page);
recordsMetaMap.put("rpp", rpp);
eventsResultMap.put("_metadata", recordsMetaMap);
log.info("The events you have queried for are:" + eventsResultMap);
return eventsResultMap;
}
請指引我哪裏做錯了。自定義配置需要完成。
我從春季官方文檔中採取了Reference。
我不認爲它正在閱讀方法。例如,它被寫爲'@ GET',但在圖片中顯示爲'POST'和其他類型。只是一個想法....我認爲'es'是由於'HashMap'的返回類型。你有沒有嘗試過使用'@ ApiOperation'註解? – Raj