• springmvc的注解开发


    springmvc的注解开发

    1. 配置DispatcherServlet

      <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:springmvc-servlet.xml</param-value>
          </init-param>
          <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
          <servlet-name>springmvc</servlet-name>
          <url-pattern>/</url-pattern>
      </servlet-mapping>
      
    2. spring配置文件springmvc-servlet.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:mvc="http://www.springframework.org/schema/mvc"
             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
              http://www.springframework.org/schema/mvc
              http://www.springframework.org/schema/mvc/spring-mvc.xsd">
          
          <!--自动扫描包,让指定包下的注解生效,由IOC容器统一管理-->
          <context:component-scan base-package="cn.pinked.controller"/>
          <!--过滤默认的静态资源-->
          <mvc:default-servlet-handler/>
          <!--注解驱动-->
          <mvc:annotation-driven/>
          <!--视图解析器-->
          <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
              <property name="prefix" value="/WEB-INF/jsp/"/>
              <property name="suffix" value=".jsp"/>
          </bean>
          
      </beans>
      
    3. 控制器

      @Controller
      public class HelloController {
          //真实路径
          @RequestMapping("/hello")
          public String hello(Model model) {
              //封装数据
              model.addAttribute("msg", "hello springmvc annotation");
              //返回给视图解析器拼接
              return "hello";
          }
      
      }
      
    4. hello.jsp

  • 相关阅读:
    H50055:html 页面加载完后再加载js文件 ,url带有时间戳后缀
    H50054:html 页面自动刷新 http-equiv属性
    WebGL_0015:参数值在一定范围内循环变化
    H50053:switch 判断范围
    WebGL_0014:改变相机的刷新颜色
    WebGL_0013:JQuery获取json文件 读取数据
    WebGL_0012:三维讲解导航模板 Icon方式
    H50052:按钮 禁止 选择 拖拽 右键
    滑动窗口的最大值(队列)
    MapReduce程序编写过程
  • 原文地址:https://www.cnblogs.com/pinked/p/12222776.html
Copyright © 2020-2023  润新知