您现在的位置是:首页 > 正文

spring boot视图html传参,spring boot 配置视图jsp

2024-04-01 03:45:53阅读 1

39beb3df9db7

image.png

目录结构

39beb3df9db7

image.png

prom.xml

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

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

39beb3df9db7

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写法

content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

Document

content:${content}

网站文章