SpringMVC JSP 前后台交互:配置多视图解析器

1.搭建项目

SpringMVC JSP 前后台交互:配置多视图解析器_第1张图片
  1. 创建resource/application.xml
这几个都是静态资源的映射路径,优先级顺序为:META-INF/resources > resources > static > public
# 默认值为 /**
spring.mvc.static-path-pattern=
# 默认值为 classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
spring.resources.static-locations=这里设置要指向的路径,多个使用英文逗号隔开



    
    
    

    
    
        
            
                classpath:properties/*.properties
                
            
        
    


    
    
        
        
        
        
            ${jdbc_driverClassName}
        
        
            ${jdbc_url}
        
        
            ${jdbc_username}
        
        
            ${jdbc_password}
        
    
    
    
        
    
    
    
        
        
        
    
    
    
        
        
        
        
    

  1. 创建webapp/spring-servlet.xml



    
    
    

    
    
        
        
        
    


  1. 创建resource/WEB-INF/hello.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%--核心标签--%>
<%@ page isELIgnored="false"%>



    
    Insert title here


${msg}

  1. 创建controller/HelloController.class
package com.lottery.controller;

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


@Controller
public class HelloController {

    @RequestMapping("/hello")
//    public ModelAndView sayHello(){
//        return new ModelAndView("hello","msg","Hello, how are you?");
//    }
    public String sayHello(Model model){
        model.addAttribute("msg", "Hello, how are you?");
        return "hello";
    }

}

你可能感兴趣的:(SpringMVC JSP 前后台交互:配置多视图解析器)