zoukankan      html  css  js  c++  java
  • @RequestMapping注解的使用,Controller方法返回值

    1,web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <display-name></display-name>
        <!--配置前端控制器 -->
        <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>
        <!--前段控制器设置url -->
        <servlet-mapping>
            <servlet-name>springmvc</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

    2,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:p="http://www.springframework.org/schema/p"
        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-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
        <!--配置handler -->
        <context:component-scan base-package="com.songyan.controller"></context:component-scan>
        <!--映射器 -->
        <!--适配器2  -->    
        <mvc:annotation-driven></mvc:annotation-driven>
        <!--解析器 -->
        <bean
            class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass"
                value="org.springframework.web.servlet.view.JstlView"></property>
            <property name="prefix" value="/WEB-INF/jsp/"></property>
            <property name="suffix" value=".jsp"></property>
        </bean>
    </beans>

     

    3,controller

    @Controller声明该类为Controller
    @RequestMapping("user")加在类前面:url细化,(url的一部分)
    @RequestMapping("user")加在方法前面:制定访问的url路径(url一部分)
    
    
    package com.songyan.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.servlet.ModelAndView;
    
    @Controller
    @RequestMapping("user")
    public class MyController {
        @RequestMapping("hello")
        public ModelAndView hello()
        {
            ModelAndView mav=new ModelAndView();
            mav.addObject("message","hahah");
            mav.setViewName("index");
            return mav;
            
        }
    
    }

     

     

  • 相关阅读:
    td内元素居顶,td元素不随高度的撑开而变位置
    C#连接MySql数据库的方法
    福昕阅读器注册码
    html初始化
    解决android的ListView嵌套在ScrollView中不能被滚动的问题
    popupWindow弹出来后,背景变暗,半透明
    android自定义radiobutton样式文字颜色随选中状态而改变
    下拉刷新
    android去掉顶部标题栏
    android使用微软雅黑字体
  • 原文地址:https://www.cnblogs.com/excellencesy/p/9186118.html
Copyright © 2011-2022 走看看