spring boot 配置视图jsp

spring boot 配置视图jsp_第1张图片
image.png

目录结构


spring boot 配置视图jsp_第2张图片
image.png

prom.xml



    4.0.0

    com.example
    demo
    0.0.1-SNAPSHOT
    war

    demo
    Demo project for Spring Boot

    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.6.RELEASE
         
    

    
        UTF-8
        UTF-8
        1.8
    

    

        
            org.springframework.boot
            spring-boot-starter-web
        
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        


        
        
            org.apache.tomcat.embed
            tomcat-embed-jasper
            
        

        
        
            org.springframework.boot
            spring-boot-starter-tomcat
            provided
        

        
            javax.servlet
            jstl
        
        
            org.springframework.boot
            spring-boot-devtools
        

    


    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    




配置 application.yml
D:\www\demo\src\main\resources\application.yml

spring:
  mvc:
    view:
      prefix: /views/
      suffix: .jsp
server:
  port: 8081

controller
D:\www\demo\src\main\java\com\example\demo\web\index.java


@controller
@RequestMapping("/index")

public class index {
    @RequestMapping("/hello")
    public String hello() {
        Map map1 = new HashMap<>();
        map1.put("hello", "fuck");
        return "index";
    }
}

controller reutrn string就是到jsp
如果放回map呢?就是json?
验证ing

spring boot 配置视图jsp_第3张图片
image.png

你是对的

传json出来

controller 写法

package com.example.demo.web.json;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class JsonIndex {
    @RequestMapping("/index")
    public Map index() {
        Map a = new HashMap();
        a.put("name", "liumingtai");
        return a;
    }
}

给jsp参数

controller写法

package com.example.demo.web.view;


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

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/index")
public class index {
    @RequestMapping("/hello")
    public String hello() {
        Map map1 = new HashMap<>();
        map1.put("hello", "fuck");
        return "index";
    }

    @RequestMapping("/jspgetvalue")
    public String ineedjson(Map map) {
        map.put("content", "将属性值传递给jsp页面");
        return "index1";
    }

    @RequestMapping("/json")
    public Map putjson(Map map) {
        map.put("content", "将属性值传递给jsp页面");
        return map;
    }
}


jsp写法



    
    
    
    Document


content:${content}


你可能感兴趣的:(spring boot 配置视图jsp)