一. 进入https://start.spring.io 快速创建项目

二. 利用eclipse sts插件创建项目

1. 安装sts插件

三.创建spring boot 项目详细步骤

1.目录结构

2.pom.xml 依赖

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.1.5.RELEASE</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.example</groupId>
  12. <artifactId>jjsp</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <packaging>war</packaging>
  15. <name>jjsp</name>
  16. <description>jsp project for Spring Boot</description>
  17.  
  18. <properties>
  19. <java.version>1.8</java.version>
  20. </properties>
  21.  
  22. <dependencies>
  23. <dependency>
  24. <groupId>org.springframework.boot</groupId>
  25. <artifactId>spring-boot-starter-web</artifactId>
  26. </dependency>
  27.  
  28. <dependency>
  29. <groupId>org.springframework.boot</groupId>
  30. <artifactId>spring-boot-starter-tomcat</artifactId>
  31. <scope>provided</scope>
  32. </dependency>
  33. <dependency>
  34. <groupId>org.springframework.boot</groupId>
  35. <artifactId>spring-boot-starter-test</artifactId>
  36. <scope>test</scope>
  37. </dependency>
  38. <dependency>
  39. <groupId>javax.servlet</groupId>
  40. <artifactId>jstl</artifactId>
  41. </dependency>
  42. <!-- To compile JSP files -->
  43. <dependency>
  44. <groupId>org.apache.tomcat.embed</groupId>
  45. <artifactId>tomcat-embed-jasper</artifactId>
  46. <scope>provided</scope>
  47. </dependency>
  48. </dependencies>
  49.  
  50. <build>
  51. <plugins>
  52. <plugin>
  53. <groupId>org.springframework.boot</groupId>
  54. <artifactId>spring-boot-maven-plugin</artifactId>
  55. </plugin>
  56. </plugins>
  57. </build>
  58.  
  59. </project>

3.Spring Boot应用程序初始化程序

  生成可部署war文件的第一步是提供SpringBootServletInitializer子类并覆盖其configure()方法。这利用了Spring Framework的Servlet 3.0支持,并允许您在servlet容器启动时配置应用程序。

  1. package com.example.jjsp.controller;
  2.  
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5.  
  6. @SpringBootApplication
  7. public class JjspApplicatio1n {
  8.  
  9. public static void main(String[] args) {
  10. SpringApplication.run(JjspApplicatio1n.class, args);
  11. }
  12. }
  1. package com.example.jjsp.controller;
  2.  
  3. import org.springframework.boot.builder.SpringApplicationBuilder;
  4. import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
  5.  
  6. public class ServletInitializer extends SpringBootServletInitializer {
  7.  
  8. @Override
  9. protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  10. return application.sources(JjspApplicatio1n.class);
  11. }
  12.  
  13. }

4. spring controller

  1. package com.example.jjsp.controller;
  2.  
  3. import java.util.Map;
  4.  
  5. import org.springframework.stereotype.Controller;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7.  
  8. @Controller
  9. public class IndexController {
  10.  
  11. @RequestMapping("/")
  12. public String home(Map<String, Object> model) {
  13. model.put("message", "HowToDoInJava Reader !!");
  14. return "index";
  15. }
  16.  
  17. @RequestMapping("/next")
  18. public String next(Map<String, Object> model) {
  19. model.put("message", "You are in new page !!");
  20. return "next";
  21. }
  22.  
  23. }

5.Spring Boot JSP ViewResolver配置

要解析JSP文件位置,可以使用两种方法。

1)在application.properties中添加条目

  1. spring.mvc.view.prefix=/WEB-INF/view/
  2. spring.mvc.view.suffix=.jsp
  3.  
  4. logging.level.org.springframework=TRACK
  5. logging.level.com=TRACK

2)配置InternalResourceViewResolver以提供JSP页面

  1. package com.example.jjsp.controller;
  2.  
  3. import org.springframework.context.annotation.ComponentScan;
  4. import org.springframework.context.annotation.Configuration;
  5. import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  6. import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
  7. import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  8. import org.springframework.web.servlet.view.InternalResourceViewResolver;
  9. import org.springframework.web.servlet.view.JstlView;
  10.  
  11. @Configuration
  12. @EnableWebMvc
  13. @ComponentScan
  14. public class MvcConfiguration extends WebMvcConfigurerAdapter
  15. {
  16. @Override
  17. public void configureViewResolvers(ViewResolverRegistry registry) {
  18. InternalResourceViewResolver resolver = new InternalResourceViewResolver();
  19. resolver.setPrefix("/WEB-INF/view/");
  20. resolver.setSuffix(".jsp");
  21. resolver.setViewClass(JstlView.class);
  22. registry.viewResolver(resolver);
  23. }
  24. } 

6.

spring boot 项目的创建的更多相关文章

  1. 1.关于SPring Boot项目的创建

    一.引入依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spri ...

  2. spring boot学习01【搭建环境、创建第一个spring boot项目】

    1.给eclipse安装spring boot插件 Eclipse中安装Spring工具套件(STS): Help -> Eclipse Marketplace... 在Search标签或者Po ...

  3. 从零开始的Spring Boot(1、搭建一个Spring Boot项目Hello World)

    搭建一个Spring Boot项目Hello World 写在前面 从零开始的Spring Boot(2.在Spring Boot中整合Servlet.Filter.Listener的方式):http ...

  4. [转] 使用Spring Boot和Gradle创建项目

    Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的 ...

  5. 使用Spring Boot和Gradle创建AngularJS项目

    Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的 ...

  6. 创建一个 Spring Boot 项目,你会几种方法?

    我最早是 2016 年底开始写 Spring Boot 相关的博客,当时使用的版本还是 1.4.x ,文章发表在 CSDN 上,阅读量最大的一篇有 42W+,如下图: 2017 年由于种种原因,就没有 ...

  7. Spring Boot入门(一):使用IDEA创建Spring Boot项目并使用yaml配置文件

    由于公司最近在做技术转型(从.Net转Java),因此自己也开启了学习Java之路.学习Java怎么能不学习这几年这么火的Spring Boot框架,由于自己有总结的习惯,因此会把学习的过程以博客的形 ...

  8. [转]通过Spring Boot三分钟创建Spring Web项目

    来源:https://www.tianmaying.com/tutorial/project-based-on-spring-boot Spring Boot简介 接下来我们所有的Spring代码实例 ...

  9. Eclipse创建第一个Spring Boot项目

    一.安装SpringBoot插件 安装过程需要联网下载插件,属于在线安装,请耐心等待安装完成,下载安装完成以后,需要重启Eclipse 二.创建Spring Boot项目 如下图所示new-other ...

随机推荐

  1. 力扣 -- 寻找两个有序数组的中位数 Median of Two Sorted Arrays python实现

    题目描述: 中文: 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2. 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n)). 你可以假设 nums ...

  2. Java集合和数组的比较(为什么引入集合)

    数组不是面向对象的,存在明显的缺陷,集合完全弥补了数组的一些缺点,比数组更灵活更实用,可大大提高软件的开发效率而且不同的集合框架类可适用于不同场合.具体如下: 1)数组的效率高于集合类. 2)数组能存 ...

  3. curl分析请求的各个部分耗时情况

    curl 命令提供了 -w 参数,解释如下 -w, --write-out Make curl display information on stdout after a completed tran ...

  4. Eigen ,MKL和 matlab 矩阵乘法速度比较

    Eigen 矩阵乘法的速度  < MKL矩阵乘法的速度,MKL矩阵乘法的速度与matlab矩阵乘法的速度相差不大,但matlab GPU版本的矩阵乘法速度是CUP的两倍,在采用float数据类型 ...

  5. python 字符串中替换字符

    今天本来打算写个程序,替换字符串中固定的一个字符:将<全部替换成回车'\n' 于是,我写成这样 s='sdjj<ddd<denj,>' for x in s: if x=='& ...

  6. 设置php的环境变量 php: command not found

    执行远程服务器上的某个脚本,却报错,提示php:command not found 找不到php命令 which php  结果是/usr/local/php/bin/php echo $PATH 结 ...

  7. 最近开发的项目,遇到用户上传excel文件并导入数据到系统这个需求,而有excel中有的单元格是日期格式,本文介绍怎么从excel中读取日期格式的数据。

    可以先判断单元格的类型,有的日期是字符串存储的,有的是按日期存储的(单元格按数字解析),代码如下: Cell cell = row.getCell(); Date date = null; if (c ...

  8. Django学习笔记(三)视图

    构建网页内容 视图函数的return具有多种响应类型: 上述函数主要来自django.http,该模块是实现响应功能的核心. 实际开发中可用此模块实现文件下载功能,在index的urls.py和vie ...

  9. springboot关联Mybatis和Redis依赖

    <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...

  10. SQL Server 2014 安装说明

    SQL Server 2014 安装说明 本节内容将说明如何通过安装向导在 Windows Server 2012 R2 上安装 SQL Server 2014. 先从 MSDN 网站上下载安装了 S ...