本文整理匯總了Java中org.springframework.web.bind.annotation.RestController類的典型用法代碼示例。如果您正苦於以下問題:Java RestController類的具體用法?Java RestController怎麽用?Java RestController使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RestController類屬於org.springframework.web.bind.annotation包,在下文中一共展示了RestController類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isAsyncRequest
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
/**
* 判斷請求是否是異步請求
* @param request
* @param handler
* @return
*/
public static boolean isAsyncRequest(HttpServletRequest request, Object handler){
boolean isAsync = false;
if(handler instanceof HandlerMethod){
HandlerMethod handlerMethod = (HandlerMethod) handler;
isAsync = handlerMethod.hasMethodAnnotation(ResponseBody.class);
if(!isAsync){
Class<?> controllerClass = handlerMethod.getBeanType();
isAsync = controllerClass.isAnnotationPresent(ResponseBody.class) || controllerClass.isAnnotationPresent(RestController.class);
}
if(!isAsync){
isAsync = ResponseEntity.class.equals(handlerMethod.getMethod().getReturnType());
}
}
if(!isAsync){
isAsync = HttpUtils.isAsynRequest(request);
}
return isAsync;
}
示例2: petApi
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
@Bean
public Docket petApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(withClassAnnotation(RestController.class))
.build()
.pathMapping("/")
.enableUrlTemplating(true)
.apiInfo(apiInfo())
.ignoredParameterTypes(
HttpServletRequest.class,
HttpServletResponse.class,
HttpSession.class,
Pageable.class,
Errors.class
);
}
示例3: process
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Set<? extends Element> elementsAnnotatedWithRestController = roundEnv.getElementsAnnotatedWith(RestController.class);
for (Element restControllerAnnotatedElement: elementsAnnotatedWithRestController) {
if (restControllerAnnotatedElement.getKind() != ElementKind.CLASS) {
error(restControllerAnnotatedElement, "@%s can be applied only to class",
RestController.class.getSimpleName());
return true;
}
if (Objects.isNull(restControllerAnnotatedElement.getAnnotation(RequestMapping.class))) {
warn(restControllerAnnotatedElement, "%s without @RequestMapping will not produce any @Test methods.",
restControllerAnnotatedElement.getSimpleName().toString());
}
// @RequestMapping 붙은 클래스
TypeElement restControllerTypeElement = (TypeElement) restControllerAnnotatedElement;
// 분석용 래퍼 클래스
RestControllerModel restControllerModel = new RestControllerModel(restControllerTypeElement);
generateStubFileFor(restControllerModel);
}
return false;
}
示例4: getSpringClassAnnotation
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
private Annotation getSpringClassAnnotation(Class clazz) {
Annotation classAnnotation = AnnotationUtils.findAnnotation(clazz, Component.class);
if (classAnnotation == null) {
classAnnotation = AnnotationUtils.findAnnotation(clazz, Controller.class);
}
if (classAnnotation == null) {
classAnnotation = AnnotationUtils.findAnnotation(clazz, RestController.class);
}
if (classAnnotation == null) {
classAnnotation = AnnotationUtils.findAnnotation(clazz, Service.class);
}
if (classAnnotation == null) {
classAnnotation = AnnotationUtils.findAnnotation(clazz, Repository.class);
}
return classAnnotation;
}
示例5: api
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
// .paths(paths())
.build().pathMapping("/").directModelSubstitute(LocalDate.class, String.class)
.genericModelSubstitutes(ResponseEntity.class).useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET, newArrayList(new ResponseMessageBuilder().code(500).message("500 message")
.responseModel(new ModelRef("Error")).build()));
}
示例6: api
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("api")
.select()
.apis(withClassAnnotation(RestController.class))
.paths(PathSelectors.regex("/api/.+"))
.build()
.apiInfo(apiInfo());
}
示例7: internal
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
@Bean
public Docket internal() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("internal")
.select()
.apis(withClassAnnotation(RestController.class))
.paths(PathSelectors.regex("/internal/.+"))
.build()
.apiInfo(apiInfo());
}
示例8: init
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
private void init(ApplicationContext context) {
init();
LOGGER.debug("Get All ExceptionHandlers");
List<Object> exceptionsHandlers = ReflectionUtils
.proxyToObject(context.getBeansWithAnnotation(ControllerAdvice.class).values());
LOGGER.debug("Get All RestController");
exceptionsHandlers.forEach(this::buildHttpCodes);
controllers
.addAll(ReflectionUtils.proxyToObject(context.getBeansWithAnnotation(RestController.class).values()));
LOGGER.debug("Get All Controller");
controllers.addAll(ReflectionUtils.proxyToObject(context.getBeansWithAnnotation(Controller.class).values()));
}
示例9: isAjax
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
/**
* 判斷是否ajax請求
* spring ajax 返回含有 ResponseBody 或者 RestController注解
* @param handlerMethod HandlerMethod
* @return 是否ajax請求
*/
public static boolean isAjax(HandlerMethod handlerMethod) {
ResponseBody responseBody = handlerMethod.getMethodAnnotation(ResponseBody.class);
if (null != responseBody) {
return true;
}
RestController restAnnotation = handlerMethod.getBeanType().getAnnotation(RestController.class);
if (null != restAnnotation) {
return true;
}
return false;
}
示例10: isJson
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
/**
* 判斷整個類裏的所有接口是否都返回json
*
* @param classz
* @return
*/
protected boolean isJson(Class<?> classz) {
Controller controllerAnno = classz.getAnnotation(Controller.class);
RestController restControllerAnno = classz.getAnnotation(RestController.class);
ResponseBody responseBody = classz.getAnnotation(ResponseBody.class);
if (responseBody != null) {
return true;
} else if (controllerAnno != null) {
return false;
} else if (restControllerAnno != null) {
return true;
}
return false;
}
示例11: filter
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
@Override
public boolean filter(Class<?> classz) {
if (classz.getAnnotation(RequestMapping.class) != null
|| classz.getAnnotation(Controller.class) != null
|| classz.getAnnotation(RestController.class) != null) {
return true;
}
return false;
}
示例12: matches
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
@Override
public boolean matches(Method method, Class<?> aClass) {
boolean support = AopUtils.findAnnotation(aClass, Controller.class) != null
|| AopUtils.findAnnotation(aClass, RestController.class) != null
|| AopUtils.findAnnotation(aClass, method, Authorize.class) != null;
if (support && autoParse) {
defaultParser.parse(aClass, method);
}
return support;
}
示例13: api
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("default")
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build()
.protocols(Sets.newHashSet(getSwaggerConfig().getString(SWAGGER_PROTOCOL)))
.apiInfo(apiInfo())
.securitySchemes(newArrayList(securitySchema()))
.securityContexts(newArrayList(securityContext()))
// .operationOrdering(getOperationOrdering()) try with swagger 2.7.0
.tags(
new Tag("alert triggers", "Operations to manage alert triggers"),
new Tag("applications", "Operations to list organization applications"),
new Tag("application document store", "Operations to manage generic documents storage"),
new Tag("device configs", "Operations to manage device configurations"),
new Tag("device credentials", "Operations to manage device credentials (username, password and URLs)"),
new Tag("device firmwares", "Operations to manage device firmwares"),
new Tag("device models", "Operations to manage device models"),
new Tag("device status", "Operations to verify the device status"),
new Tag("devices", "Operations to manage devices"),
new Tag("devices custom data", "Operations to manage devices custom data"),
new Tag("events", "Operations to query incoming and outgoing device events"),
new Tag("gateways", "Operations to manage gateways"),
new Tag("locations", "Operations to manage locations"),
new Tag("rest destinations", "Operations to list organization REST destinations"),
new Tag("rest transformations", "Operations to manage REST transformations"),
new Tag("routes", "Operations to manage routes"),
new Tag("users", "Operations to manage organization users"),
new Tag("user subscription", "Operations to subscribe new users")
)
.enableUrlTemplating(false);
}
示例14: getSupportedAnnotationTypes
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
@Override
public Set<String> getSupportedAnnotationTypes() {
Set<String> annotataions = new LinkedHashSet<String>();
annotataions.add(org.springframework.web.bind.annotation.RestController.class.getCanonicalName());
return annotataions;
}
示例15: postProcessBeanFactory
import org.springframework.web.bind.annotation.RestController; //導入依賴的package包/類
@Override
public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException {
Map<RequestMethod, Integer> methodsCount = new HashMap<RequestMethod, Integer>();
String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames();
for (String beanDefinitionName : beanDefinitionNames) {
Class<?> type = beanFactory.getType(beanDefinitionName);
RestController annotation = type.getAnnotation(RestController.class);
if (annotation != null) {
Method[] methods = type.getMethods();
processControllerMethods(methods, methodsCount);
}
}
Integer allMethodCount = 0;
for (Entry<RequestMethod, Integer> methodCount : methodsCount.entrySet()) {
LOGGER.info("Http Method - {} : {}", methodCount.getKey(), methodCount.getValue());
allMethodCount += methodCount.getValue();
}
LOGGER.info("All methods count: {}", allMethodCount);
beanFactory.registerSingleton("httpMethodsCount", allMethodCount);
beanFactory.registerSingleton("httpMethods", methodsCount);
}