5. thymeleaf获取作用域中对象的数据和URL表达式

一 获取作用域中对象的数据

  1. 创建congtroller
@RequestMapping("/show5")
	public String showInfo5(HttpServletRequest request ,Model model) {
		request.setAttribute("req", "HttpServletRequest");
		request.getSession().setAttribute("sess", "HttpSession");
		request.getSession().getServletContext().setAttribute("con", "contenxt");
		return "index5";
	}

2.编写index5





Insert title here


request:
session:
Context:


二 URL表达式

  1. 创建controller
package com.synda.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

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

/**
 * thymeleaf-URL
 * @author admin
 *
 */
@Controller
public class DemoController {
	
	@RequestMapping("/{page}")
	public String showInfo(@PathVariable String page ,String id) {
		System.out.println(id);
		return page;
	}
}

2 . 页面





thymeleaf-URL


绝对路径
绝对路径

相对路径-相对于当前项目的根
相对于服务器路径的根

参数传递



你可能感兴趣的:(SpringBoot)