(41)Spring MVC (2023-3-31)

Spring mvc使用必做?

        两件事: 

①在web.xml中配置ContextLoaderListener监听器(导入spring-web坐标)

②使用WebApplicationContextUtils获得应用上下文对象ApplicationContext

导入Spring集成web的坐标


    org.springframework
    spring-web
    5.0.5.RELEASE

配置ContextLoaderListener监听器



    contextConfigLocation
    classpath:applicationContext.xml



	
       org.springframework.web.context.ContextLoaderListener
   
 

SpringMVC快速入门

需求:客户端发起请求,服务器端接收请求,执行逻辑并进行视图跳转。

开发步骤

①导入SpringMVC相关坐标

②配置SpringMVC核心控制器DispathcerServlet

③创建Controller类和视图页面

④使用注解配置Controller类中业务方法的映射地址

⑤配置SpringMVC核心文件 spring-mvc.xml

⑥客户端发起请求测试

代码实现

①导入Spring和SpringMVC的坐标、导入Servlet和Jsp的坐标

②在web.xml配置SpringMVC的核心控制器

③创建Controller和业务方法

③创建视图页面index.jsp

④配置注解

⑤创建spring-mvc.xml

⑥访问测试地址

你可能感兴趣的:(spring,mvc,java)