1、前端页面
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>字面量</title>
</head>
<body>
<h1>文本字面量用单引号'......'的字符串就是字面量</h1>
<a th:href="@{'/second?id=' + ${id}}">查看学生学号</a><br><br><br>
<!--th:text="Hello"中不能带有符号-->
<span th:text="Hello"></span><br><br>
<h1>数字字面量</h1>
今年是<span th:text="2020">1949</span>年<br>
20年后是<span th:text="2040">1969</span>年<br>
</body>
</html>
2、后台控制器
package com.springboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@RequestMapping("/first")
public String doFirst(Model model){
model.addAttribute("id", 1001);
System.out.println("------------------");
return "literal";
}
@RequestMapping("/second")
@ResponseBody
public Object doSecond(Integer id){
return "学生学号id = " + id;
}
}