@Controller注解


package org.springframework.stereotype;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * Indicates that an annotated class is a "Controller" (e.g. a web controller).
 *  * <p>This annotation serves as a specialization of {@link Component @Component},
 * allowing for implementation classes to be autodetected through classpath scanning.
 * It is typically used in combination with annotated handler methods based on the
 * {@link org.springframework.web.bind.annotation.RequestMapping} annotation.
 *  * @author Arjen Poutsma
 * @author Juergen Hoeller
 * @since 2.5
 * @see Component
 * @see org.springframework.web.bind.annotation.RequestMapping
 * @see org.springframework.context.annotation.ClassPathBeanDefinitionScanner
 */
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller {

	/**
	 * The value may indicate a suggestion for a logical component name,
	 * to be turned into a Spring bean in case of an autodetected component.
	 * @return the suggested component name, if any
	 */
	String value() default "";
}

@Controller注解:

  • 用在类上面,表示这个类是一个Controller,比如web controller
  • 该注解可以被当作是@Component注解的一个特殊实现
  • 允许通过类路径扫描自动检测实现类
  • 它通常是和基于注解@RequestMapping的方法结合使用的
  • 该注解有一个默认方法,返回类型为Stringvalue的值默认为空
  • value的值可能是逻辑组件的名称,如果有自动检测到的组件,则将其转换为Spring bean
发布了453 篇原创文章 · 获赞 539 · 访问量 156万+

猜你喜欢

转载自blog.csdn.net/u012934325/article/details/105032845