thymeleaf将对象Model数据抛到HTML页面
thymeleaf名称空间
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> 111 </body> </html>
thymeleaf读取model中的数据
创建实体类
package com.zystest.myxuexi.Model; public class Student { private String name; private String pwd; private String sex; public Student(String name, String pwd, String sex) { this.name = name; this.pwd = pwd; this.sex = sex; } @Override public String toString() { return "Student{" + "name='" + name + '\'' + ", pwd='" + pwd + '\'' + ", sex='" + sex + '\'' + '}'; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPwd() { return pwd; } public void setPwd(String pwd) { this.pwd = pwd; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } }
创建相关页面
·
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Student</title> </head> <body > <div th:text="${student.name}">1</div> <div th:text="${student.pwd}">2</div> <div th:text="${student.sex}">3</div> <br> <br> <br> </body> </html>