本文整理汇总了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);
}