整合持久层技术
整合jsp
整合frameworker
整合thymeleaf
整合jsp技术
pom文件
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.2.0.RELEASE
com.pshdhx
01-springboot-view-jsp
0.0.1-SNAPSHOT
1.8
org.springframework.boot
spring-boot-starter-web
javax.servlet
jstl
org.apache.tomcat.embed
tomcat-embed-jasper
provided
9.0.8
配置文件application.properities
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
实体类User.java
package com.pshdhx.controller;
public class User {
private String id;
private String userName;
private int age;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public User(String id, String userName, int age) {
super();
this.id = id;
this.userName = userName;
this.age = age;
}
}
控制层JSPController.java
package com.pshdhx.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**
*
* @author ASUS
*
*/
@Controller
public class JSPController {
/*
* 处理请求,产生数据
*/
@RequestMapping("/showUser")
public String showUser(Model model){
List list = new ArrayList<>();
list.add(new User("1","张三",20));
list.add(new User("2","李四",22));
list.add(new User("3","王五",24));
//需要一个 Model 对象
model.addAttribute("list", list);
//跳转视图
return "userList";
}
}
视图层userList.jsp
pageEncoding="UTF-8"%>
Insert title hereID | NAME | AGE |
---|---|---|
${user.id } | ${user.userName } | ${user.age } |
主启动类App.java
package com.pshdhx;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
目录结构
访问地址: