1、在类上加上注解@controller
@Controller
public class HelloController {
}
2、在配置文件中扫描
<!--扫描控制层组件-->
<context:component-scan base-package="com.atguigu.mvc.controller"></context:component-scan>
Spring MVC:使用@Controller注解与配置扫描
本文介绍了在Spring MVC中如何使用@Controller注解来标记控制器类,并在配置文件中通过<context:component-scan>进行组件扫描,实现控制层的自动加载。通过这种方式,可以简化Spring应用的配置并提高开发效率。
1、在类上加上注解@controller
@Controller
public class HelloController {
}
2、在配置文件中扫描
<!--扫描控制层组件-->
<context:component-scan base-package="com.atguigu.mvc.controller"></context:component-scan>
356
2790

被折叠的 条评论
为什么被折叠?
打赏作者