zoukankan      html  css  js  c++  java
  • [一]初识SpringMVC

    是什么?

      web开发框架

    为什么用?

      功能强大

    怎么做?

      1.导入jar包

      2.配置web.xml

        

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <display-name>SpringMvc01</display-name>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>

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

      3.编写springmvc.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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- 使用注解的包,包括子集 -->
    <context:component-scan base-package="com.lxl"/>

    <!-- 视图解析器 -->
    <bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp"></property>
    </bean>

    </beans>

      4.编写Controller

        

    package com.lxl.controller;

    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;

    @Controller
    public class HelloWorldController {

    @RequestMapping("/helloWorld")
    public String helloWorld(Model model){
    model.addAttribute("message", "hello world!");
    return "helloWorld";
    }
    }

  • 相关阅读:
    Hive 中parse_url的使用
    作为首席架构师,我是如何选择并落地架构方案的?
    漫谈数据仓库之拉链表(原理、设计以及在Hive中的实现)
    纸上得来终觉浅
    年薪50万的大数据分析师养成记【摘抄】
    如果有人问你数据库的原理,叫他看这篇文章(完)
    开源大数据引擎:Greenplum 数据库架构分析
    【阿里在线技术峰会】李金波:企业大数据平台仓库架构建设思路
    ETL Automation完整安装方法_(元数据存放在mysql数据库)
    js定时器 离开当前页面任然执行的问题
  • 原文地址:https://www.cnblogs.com/luoxiaolei/p/5090151.html
Copyright © 2011-2022 走看看