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";
    }
    }

  • 相关阅读:
    android学习之4种点击事件的响应方式
    python Eve RESTFul 尝试笔记
    完成端口学习笔记(一):完成端口+控制台 实现文件拷贝
    POJ3080:Blue Jeans
    如何让ros支持C++11标准
    ros卸载
    文件读写
    sys.exit()主动结束程序
    python函数查询、数学和比较操作符、二元操作符
    labellmg使用方法
  • 原文地址:https://www.cnblogs.com/luoxiaolei/p/5090151.html
Copyright © 2011-2022 走看看