spring boot 1.5.4 整合JSP(四)

本文详细介绍如何在Spring Boot项目中集成JSP页面,包括配置Maven依赖、启动类、控制器及视图展示等内容。

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

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

   <modelVersion>4.0.0</modelVersion>

   <parent>

      <!--spring boot项目的parent -->

      <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-starter-parent</artifactId>

      <version>1.5.4.RELEASE</version>

   </parent>

   <groupId>com.wyait.boot</groupId>

   <artifactId>spring-boot-jsp</artifactId>

   <version>0.0.1-SNAPSHOT</version>

   <packaging>war</packaging>

 

   <dependencies>

      <dependency>

        <!--spring boot 引入Web模块。自动配置:tomcatspringmvcjackson -->

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-web</artifactId>

      </dependency>

      <!--tomcat 的支持. -->

      <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-tomcat</artifactId>

        <!--添加<scope>provided</scope>,因为provided表明该包只在编译和测试的时候用 -->

        <scope>provided</scope>

      </dependency>

      <dependency>

        <groupId>org.apache.tomcat.embed</groupId>

        <artifactId>tomcat-embed-jasper</artifactId>

        <scope>provided</scope>

      </dependency>

      <dependency>

        <groupId>javax.servlet</groupId>

        <artifactId>jstl</artifactId>

      </dependency>

   </dependencies>

   <build>

      <plugins>

        <plugin>

           <!--配置spring bootmaven插件 -->

           <groupId>org.springframework.boot</groupId>

           <artifactId>spring-boot-maven-plugin</artifactId>

        </plugin>

      </plugins>

   </build>

</project>

   配置application.properties,并添加jsp支持

wKiom1nDHFvBITusAABDzcCunqk928.png

   编写DemoApplication

wKioL1nDHC_SPZoLAABSJeO_npE612.png

   编写Controller  user对象

wKioL1nDHDjTZ9K7AAANyhVkSmU637.pnggetter/setter方法自动生成//TODO

@Controller

public class HelloController {

 

   /**

    *

    * @描述:跳转到thymeleaf页面

    * @创建人:wyait

    * @创建时间:201762710:40:22

    * @param map

    * @return

    */

   @RequestMapping("/hello")

   publicString toDemo(ModelMap map) {

      Useruser = new User();

      user.setId(5L);

      user.setAge(26);

      user.setName("张三");

      map.addAttribute("user",user);

      return"hello";

   }

}

   编写jsp页面

<%@ pagelanguage="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<metahttp-equiv="Content-Type" content="text/html;charset=UTF-8"/>

<title>This is Spring Bootjsp</title>

</head>

<body>

   <h2>这是一个jsp页面</h2>

   <hr/>

   <p>我叫${user.name },今年${user.age },编号:${user.id}</p>

</body>

</html>

 

   启动,访问:http://127.0.0.1:8080/hello

wKiom1nDHHbAQmLaAABBiSAnSDw372.png



本文转自 wyait 51CTO博客,原文链接:http://blog.51cto.com/wyait/1967356,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值