• springmvc快速入门(注解版本)


    1)springmvc快速入门(传统版)

       步一:创建springmvc-day02这么一个web应用

       步二:导入springioc,springweb和springmvc相关的jar包

      ------------------------------------------------------springWEB模块
       org.springframework.web-3.0.5.RELEASE.jar
    org.springframework.web.servlet-3.0.5.RELEASE.jar(mvc专用)
       ------------------------------------------------------springIOC模块
       org.springframework.asm-3.0.5.RELEASE.jar
       org.springframework.beans-3.0.5.RELEASE.jar
       org.springframework.context-3.0.5.RELEASE.jar
       org.springframework.core-3.0.5.RELEASE.jar
       org.springframework.expression-3.0.5.RELEASE.jar

    步三:在/WEB-INF/下创建web.xml文件

    <servlet>
            <servlet-name>DispatcherServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>classpath:spring.xml</param-value>
            </init-param>
        </servlet>
        <servlet-mapping>
            <servlet-name>DispatcherServlet</servlet-name>
            <url-pattern>*.action</url-pattern>
        </servlet-mapping>

    步四:创建HelloAction.java控制器类

    @Controller
    public class HelloAction{
        @RequestMapping(value="/hello")
        public String helloMethod(Model model) throws Exception{
            System.out.println("HelloAction::helloMethod()");
            model.addAttribute("message","这是我的第二个springmvc应用程序");
            return "/success.jsp";
        }    
    }

    步五:在/WebRoot/下创建success.jsp

    <%@ page language="java" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>这是我的第二个springmvc应用程序</title>
      </head>
      <body>
        success.jsp<br/>
        ${message}
      </body>
    </html>

    步六:在/src/目录下创建spring.xml配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans 
          xmlns="http://www.springframework.org/schema/beans"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:context="http://www.springframework.org/schema/context"
          xmlns:aop="http://www.springframework.org/schema/aop"
          xmlns:tx="http://www.springframework.org/schema/tx"
          xmlns:mvc="http://www.springframework.org/schema/mvc"
            
          xsi:schemaLocation="
        
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
        
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            
          ">
            
    
          <!-- Action控制器 -->
          <context:component-scan base-package="loaderman.javaee.springmvc.helloannotation"/>      
    
          
          
          <!-- 基于注解的映射器(可选) -->
          <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
          
          <!-- 基于注解的适配器(可选) -->
          <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
          
          <!-- 视图解析器(可选) -->
          <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"/>
              
    </beans>

    步七:部署web应用到tomcat中,通过浏览器访问hello.action的URL

  • 相关阅读:
    国货之光业务增长背后的技术支持
    减少运维工作量,如何通过 ROS 轻松实现资源编排新方式
    我在阿里写代码学会的六件事
    SpringCloud 应用在 Kubernetes 上的最佳实践 — 诊断(线上联调)
    视频需求超平常数 10 倍,却节省了 60% 的 IT 成本投入是一种什么样的体验?
    从单体到混乱的微服务,阿里云托管式服务网格是如何诞生的?
    阿里张磊:如何构建以应用为中心的“Kubernetes”?(内含 QA 整理)
    python之深度学习-模拟异步操作(队列)
    python之深度学习-队列处理数据(同步)
    python深度学习-tensorflow实现一个线性回归的案例
  • 原文地址:https://www.cnblogs.com/loaderman/p/10063276.html
Copyright © 2020-2023  润新知