Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >springBoot学习(五)springBoot自定义banner与web开发

springBoot学习(五)springBoot自定义banner与web开发

作者头像
杨小杰
发布于 2019-07-04 08:26:46
发布于 2019-07-04 08:26:46
75900
代码可运行
举报
运行总次数:0
代码可运行

@SpringBootApplication

该注解相关的几个方法

  • exclude,排除某些类添加至spring容器管理,参数为class对象
  • excludeName,排除某些类添加至spring容器管理,参数为class path字符串
  • scanBasePackages,将某些包下的类添加进入spring扫描文件,参数为class path字符串
  • scanBasePackageClasses,将某些包下的类添加进入spring扫描文件,参数为class对象

springBoot的banner图

不显示banner

通过 springBootTestRun.setBannerMode(Banner.Mode.OFF);

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.yxj.spring;

import com.yxj.spring.Initializer.MyApplicationContextInitializer;
import com.yxj.spring.monitor.MyApplicationListener;
import com.yxj.spring.monitor.MyEvent;
import com.yxj.spring.properties.TestProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;

import java.util.List;

/**
 * @ProjectName: springBootDemo
 * @Package: com.yxj.spring
 * @Description:
 * @Author: 阿杰
 * @CreateDate: 2019/1/18 20:18
 * @UpdateUser: 暂无
 * @UpdateDate: 2019/1/18 20:18
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */
@SpringBootApplication
public class SpringBootTestRun {

    public static void main(String[] args) {
        SpringApplication springBootTestRun = new SpringApplication(SpringBootTestRun.class);
        springBootTestRun.setBannerMode(Banner.Mode.OFF);
        ConfigurableApplicationContext run = springBootTestRun.run(args);
        run.close();
    }
}
自定义banner
方式一

在resource目录下新建banner.txt,txt放入自定义内容

方式二

在resource目录下新建自定义名称.txt,在application.properties中添加“spring.banner.location=自定义名称.txt”

方式三

自定义banner也可以是图片,会自动解析为ASCII艺术字,名称为banner.jpg/banner.png/banner.gif

方式四

自定义图片名称,通过在application.properties中添加“spring.banner.image.location=自定义名称.jpg”

在启动项目的时候,文字和图片可以共同显示,图片优先级大于文字
SpringBoot自定义启动Banner在线生成工具

https://www.bootschool.net/ascii

SpringBoot艺术字

https://www.bootschool.net/ascii-art

web开发

测试访问

pom文件

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="UTF-8"?>
<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.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.yxj.spring</groupId>
    <artifactId>springBootDemo</artifactId>
    <version>1.0.0</version>

    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
    </parent>

    <!-- Add typical dependencies for a web application -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

    <!-- Package as an executable jar -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

</project>

controller方法

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.yxj.spring.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @ProjectName: springBootDemo
 * @Package: com.yxj.spring.controller
 * @Description: @RestController表示当前controller方法的返回值可以直接用于返回值输出==@ResponseBody
 * @Author: 阿杰
 * @CreateDate: 2019/1/27 23:21
 * @UpdateUser: 暂无
 * @UpdateDate: 2019/1/27 23:21
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */
@RestController
@RequestMapping("my")
public class MyController {

    @GetMapping("testWeb")
    public String testWeb(HttpServletRequest request){
        return "测试";
    }

    @GetMapping(value = "/pathParam/{id}")
    public String pathParam(@PathVariable(value = "id") String id){
        return "测试, id = "+id;
    }
}

springBoot启动类

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.yxj.spring;

import com.yxj.spring.Initializer.MyApplicationContextInitializer;
import com.yxj.spring.monitor.MyApplicationListener;
import com.yxj.spring.monitor.MyEvent;
import com.yxj.spring.properties.TestProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;

import java.util.List;

/**
 * @ProjectName: springBootDemo
 * @Package: com.yxj.spring
 * @Description:
 * @Author: 阿杰
 * @CreateDate: 2019/1/18 20:18
 * @UpdateUser: 暂无
 * @UpdateDate: 2019/1/18 20:18
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */
@SpringBootApplication
public class SpringBootTestRun {

    public static void main(String[] args) {
        SpringApplication springBootTestRun = new SpringApplication(SpringBootTestRun.class);
        ConfigurableApplicationContext run = springBootTestRun.run(args);
    }
}

测试访问路径 http://localhost:8080/my/testWeb

指定端口

application.properties

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
server.port=80
返回jsp页面

springBoot默认不支持jsp组建,需要添加maven包 添加依赖包

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

application.properties指定前缀和后缀

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp

prefix=/,这里的/指的是webapp,为jsp根目录,idea中可以设置web根目录

webapp下新增test.jsp

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
this is test jsp , get controller param is ${testParam}
</body>
</html>

访问jsp的controller代码

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.yxj.spring.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ProjectName: springBootDemo
 * @Package: com.yxj.spring.controller
 * @Description:
 * @Author: 阿杰
 * @CreateDate: 2019/1/28 0:00
 * @UpdateUser: 暂无
 * @UpdateDate: 2019/1/28 0:00
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */
@Controller
public class JspController {

    @GetMapping(value = "/toTsetJsp/{id}")
    public ModelAndView toTsetJsp(@PathVariable String id){
        ModelAndView modelAndView = new ModelAndView("/test");
        modelAndView.addObject("testParam",id);
        return modelAndView;
    }
}
使用freemarker

加入依赖,pom.xml

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>

访问controller

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.yxj.spring.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ProjectName: springBootDemo
 * @Package: com.yxj.spring.controller
 * @Description:
 * @Author: 阿杰
 * @CreateDate: 2019/1/28 20:47
 * @UpdateUser: 暂无
 * @UpdateDate: 2019/1/28 20:47
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */
@Controller
public class FreemarkerController {

    @GetMapping(value = "/testFreeMarker/{id}")
    public ModelAndView testFreeMarker(@PathVariable(value = "id") String id){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("a");
        mv.addObject("userName",id);
        return mv;
    }
}

在resource下添加文件夹templates,其中添加a.ftl

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<h1>this is test ftl, get param is ${userName}</h1>

访问链接 http://localhost/testFreeMarker/123 访问页面,数据渲染正常

默认目录为classpath:/templates/ 源码中有个默认值

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.springframework.boot.autoconfigure.freemarker;

import java.util.HashMap;
import java.util.Map;
import org.springframework.boot.autoconfigure.template.AbstractTemplateViewResolverProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(
    prefix = "spring.freemarker"
)
public class FreeMarkerProperties extends AbstractTemplateViewResolverProperties {
    public static final String DEFAULT_TEMPLATE_LOADER_PATH = "classpath:/templates/";
    public static final String DEFAULT_PREFIX = "";
    public static final String DEFAULT_SUFFIX = ".ftl";
    private Map<String, String> settings = new HashMap();
    private String[] templateLoaderPath = new String[]{"classpath:/templates/"};
    private boolean preferFileSystemAccess = true;

    public FreeMarkerProperties() {
        super("", ".ftl");
    }

    public Map<String, String> getSettings() {
        return this.settings;
    }

    public void setSettings(Map<String, String> settings) {
        this.settings = settings;
    }

    public String[] getTemplateLoaderPath() {
        return this.templateLoaderPath;
    }

    public boolean isPreferFileSystemAccess() {
        return this.preferFileSystemAccess;
    }

    public void setPreferFileSystemAccess(boolean preferFileSystemAccess) {
        this.preferFileSystemAccess = preferFileSystemAccess;
    }

    public void setTemplateLoaderPath(String... templateLoaderPaths) {
        this.templateLoaderPath = templateLoaderPaths;
    }
}

通过在application.properties中可以配置默认路径

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
spring.freemarker.template-loader-path=classpath:/templatesTest/
切换jetty容器

springBoot默认内置的是tomcat容器,切换jetty容器,需要配置 pom文件spring-boot-starter-web排除tomcat的引用,注释掉springBoot支持jsp,该依赖会导致切换jetty成功,但是使用的依然是tomcat容器

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="UTF-8"?>
<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.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.yxj.spring</groupId>
    <artifactId>springBootDemo</artifactId>
    <version>1.0.0</version>

    <!-- Inherit defaults from Spring Boot -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
    </parent>

    <!-- Add typical dependencies for a web application -->
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!--排除tomcat的引用-->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!--使springBoot支持jsp-->
        <!--<dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>-->

        <!--使springBoot支持freemarker-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>

        <!--添加jetty依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>

    </dependencies>

    <!-- Package as an executable jar -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

</project>

重新编译,查看日志,包含有jetty字样,表示容器切换成功

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
JettyWebServer  : Jetty started on port(s) 80 (http/1.1) with context path '/'

关于jetty与tomcat区别与用途,可以查看博客https://blog.csdn.net/u014209975/article/details/52598428

静态资源读取

1.在webapp下-web根目录,在文件下面新建img,放入test.png 可以通过http://localhost/img/test.png 正常访问到 2.在resource下的这几个文件,也是可以放静态文件的,默认访问路径也是/

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
            "classpath:/META-INF/resources/", "classpath:/resources/",
            "classpath:/static/", "classpath:/public/" };

经过测试,以下两个链接可以访问到各个对应的静态图片

  • http://localhost/springBootDemo/img/test1.png
  • http://localhost/springBootDemo/img/test.png

3.可以通过在application.properties中添加参数来指定默认路径

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#修改静态资源默认访问路径(修改之后,resource下的几个默认文件地址不会生效,webapp可以正常访问)
spring.resources.static-locations=classpath:/html/
springBoot异常处理
springBoot对异常做了特殊处理
springBoot处理之后-404页面
springBoot处理之后-500页面
排除springBoot对异常处理的方式
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.yxj.spring;

import com.yxj.spring.Initializer.MyApplicationContextInitializer;
import com.yxj.spring.monitor.MyApplicationListener;
import com.yxj.spring.monitor.MyEvent;
import com.yxj.spring.properties.TestProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.Banner;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;

import java.util.List;

/**
 * @ProjectName: springBootDemo
 * @Package: com.yxj.spring
 * @Description:
 * @Author: 阿杰
 * @CreateDate: 2019/1/18 20:18
 * @UpdateUser: 暂无
 * @UpdateDate: 2019/1/18 20:18
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */

/**
 * 排除springBoot对异常的默认处理
 */
@SpringBootApplication(exclude = ErrorMvcAutoConfiguration.class)
public class SpringBootTestRun {

    public static void main(String[] args) {
        SpringApplication springBootTestRun = new SpringApplication(SpringBootTestRun.class);
        ConfigurableApplicationContext run = springBootTestRun.run(args);
    }
}
springBoot处理之前-500
springBoot处理之前-404
自定义异常处理
1.通过实现ErrorPageRegistrar接口的方式(类似web.xml中配置的errpage标签的形式)
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.yxj.spring.myException;

import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * @ProjectName: springBootDemo
 * @Package: com.yxj.spring.myException
 * @Description:
 * @Author: 阿杰
 * @CreateDate: 2019/1/29 14:51
 * @UpdateUser: 暂无
 * @UpdateDate: 2019/1/29 14:51
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */
@Component
public class CommonErrorPageRegistrar implements ErrorPageRegistrar {

    /**
     * 如果相对某个异常做单独页面的跳转处理
     * ErrorPage(Class<? extends Throwable> exception, String path)
     * 可以添加一个Class对象,和跳转路径。
     * @param registry
     */
    @Override
    public void registerErrorPages(ErrorPageRegistry registry) {
        ErrorPage ep404 = new ErrorPage(HttpStatus.NOT_FOUND,"/html/404.html");
        ErrorPage ep500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR,"/html/500.html");
        registry.addErrorPages(ep404,ep500);
    }
}
自定义异常处理的页面-404
自定义异常处理的页面-500
2.通过@ExceptionHandler注解(这个处理方式可以返回字符串或者json,可以获取到具体的异常message,通常用作全局异常处理,也可以做细分)
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
package com.yxj.spring.myException;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ProjectName: springBootDemo
 * @Package: com.yxj.spring.myException
 * @Description:
 * @Author: 阿杰
 * @CreateDate: 2019/1/29 15:18
 * @UpdateUser: 暂无
 * @UpdateDate: 2019/1/29 15:18
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */
@ControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public String handleException(Exception e){
        return "检测到异常:"+e.getMessage();
    }
}
tomcat配置
内置tomcat的log access相关配置
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#缓冲输出,定期刷新
server.tomcat.accesslog.buffered=true
#创建日志文件的目录。可以是相对于Tomcat基目录或绝对目录。
server.tomcat.accesslog.directory=d:/springBootDemoLogs
#启用日志(true会生成日志文件到directory指定的路径,false不会生成)
server.tomcat.accesslog.enabled=true
#生成的日志名称的日期格式
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd
#访问日志的格式模式 详细使用查看- https://www.cnblogs.com/chrischennx/p/6746214.html
server.tomcat.accesslog.pattern=common
#日志文件名字前缀
server.tomcat.accesslog.prefix=springBoot_demo_logs
#是否延迟在文件名中包含日期戳,直到旋转时间
server.tomcat.accesslog.rename-on-rotate=false
#设置请求的IP地址,主机名,协议和端口的请求属性
server.tomcat.accesslog.request-attributes-enabled=false
#是否启用访问日志轮换。
server.tomcat.accesslog.rotate=true
#日志文件名称的后缀
server.tomcat.accesslog.suffix=.log
tomcat最大线程数和连接数设置
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#设置tomcat的最大线程数
server.tomcat.max-threads=1000
#设置tomcat的最大连接数
server.tomcat.max-connections=20000
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-01-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 JAVA知识总结与分享 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
springBoot学习(二)配置环境动态切换和部分注解的运用
建立第一个配置文件(springBoot默认读取的文件)application.properties
乱敲代码
2019/05/30
1.1K0
springBoot学习(一)建立项目与读取配置文件
Alpha:是内部测试版,一般不向外部发布,会有很多Bug.一般只有测试人员使用。
乱敲代码
2019/05/30
1.7K0
springBoot学习(三)springBoot事件监听和部分注解的运用
1.springBoot启动类会使用@SpringBootApplication 2.点进入源代码发现改注解是一个复合注解,由好几个注解共同组合而成
乱敲代码
2019/05/30
5110
自定义redis-spring-boot-starter
3) 没有整合其它技术的小案例不完整,所以选择了个人认为简单的redis,自定义myredis-spring-boot -starter
CBeann
2023/12/25
2660
自定义redis-spring-boot-starter
一起来学 SpringBoot | 第一篇:构建第一个 SpringBoot 工程
摘要: 原创出处 http://blog.battcn.com/2018/04/20/springboot/v2-introducing/ 「唐亚峰」欢迎转载,保留摘要,谢谢!
芋道源码
2019/10/29
4440
一起来学 SpringBoot | 第一篇:构建第一个 SpringBoot 工程
springboot自定义starter
第一步:创建starter工程hello-spring-boot-starter并配置pom.xml文件
无敌小菜鸟
2022/02/23
8320
springboot自定义starter
【学习笔记】springboot教程(1)第一个demo
【学习笔记】springboot教程(1) 第一个demo 摘要: 先了解下springboot到底是个什么东西,能用来干什么?有什么好处?也就是为什么要学习他用他。然后给个网上到处都能找到的demo。 前言 1、什么是springboot? 简单的理解就是一个快速开发框架集合,大家都叫他快速开发脚手架。 2、springboot有什么特征? 它遵循“习惯由于配置”原则,使用springboot只需要少量配置,我们大部分时候可以使用他的默认配置; 它可以让我们搭建项目更快速,可无配
Java帮帮
2018/03/19
1.2K0
【学习笔记】springboot教程(1)第一个demo
Spring Boot 2.X(三):使用 Spring MVC + MyBatis + Thymeleaf 开发 web 应用
Spring MVC 是构建在 Servlet API 上的原生框架,并从一开始就包含在 Spring 框架中。本文主要通过简述 Spring MVC 的架构及分析,并用 Spring Boot + Spring MVC + MyBatis (SSM)+ Thymeleaf(模板引擎) 框架来简单快速构建一个 Web 项目。
朝雾轻寒
2019/10/18
1.4K1
Spring Boot 2.X(三):使用 Spring MVC + MyBatis + Thymeleaf 开发 web 应用
Spring Boot如何自定义Starter
如果我们系统中想要拥有自动配置的功能,可以自己编写一个starter (启动器),想想就觉得很酷,因为这意味着我们不仅有自己定义的自动配的功能,而且具有更通用的耦合度更低的配置。
Bug开发工程师
2019/05/05
6700
Spring Boot如何自定义Starter
SpringBoot拦截器
在实际开发中,总存在着这样的场景,比如拦截请求的ip地址,或者在所有的请求都返回相同的数据,如果每一个方法都写出相同数据固然可以实现,但是随着项目的变大,重复的代码会越来越多,所以在这种情况我们可以用
dalaoyang
2018/04/28
8350
SpringBoot拦截器
springBoot学习(四)项目初始化的开始和结束
用来初始化Spring ConfigurableApplicationContext应用上下文的回调接口,是在ConfigurableApplicationContext.refresh()之前调用。 该接口典型的应用场景是web应用中需要编程方式对应用上下文做初始化。比如,注册属性源(property sources)或者针对上下文的环境信息environment激活相应的profile
乱敲代码
2019/05/30
9600
SpringBoot 自定义 starter
SpringBoot 最强大的功能就是把我们常用的场景抽取成了一个个starter(场景启动器),我们通过引入springboot 为我提供的这些场景启动器,我们再进行少量的配置就能使用相应的功能。即使是这样,springboot也不能囊括我们所有的使用场景,往往我们需要自定义starter,来简化我们对springboot的使用。
jwangkun
2021/12/23
2850
SpringBoot 自定义 starter
一起来学SpringBoot | 第一篇:构建第一个SpringBoot工程
未接触 SpringBoot 之前,搭建一个普通的 WEB 工程往往需要花费30分钟左右,如果遇到点奇葩的问题耽搁的时间会更长一点,但自从用了 SpringBoot 后,真正体会到什么叫分分钟搭建一个 WEB,让我拥有更多的时间跟我的小伙伴们唠嗑了。使用 SpringBoot 后发现一切是如此的简单(还记得读书那会被JAR包,xml支配的恐惧吗,如今都可以说 good bye)
battcn
2018/08/03
8450
一起来学SpringBoot | 第一篇:构建第一个SpringBoot工程
springboot学习(一):初识SpringBoot(入门篇)
Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程。该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。通过这种方式,Spring Boot致力于在蓬勃发展的快速应用开发领域(rapid application development)成为领导者。
sunonzj
2022/06/21
4810
springboot学习(一):初识SpringBoot(入门篇)
SpringBoot高级使用
为了提高我们的开发效率,我们可以放开IDEA中的SpringBoot项目的热部署操作
Java鱼头
2022/12/01
7721
快速学习-SpringBoot入门
SpringBoot要求,项目要继承SpringBoot的起步依赖spring-boot-starter-parent
cwl_java
2020/04/01
4540
快速学习-SpringBoot入门
springboot之自定义starter
3、在该工程中点击+,选择new module,新建一个Spring Initializr工程
西西嘛呦
2020/08/26
3960
springboot之自定义starter
maven中使用springboot返回jsp和json数据
参考:http://fhd001.iteye.com/blog/1136428    ;     http://blog.csdn.net/lmy86263/article/details/51622522
克虏伯
2019/04/15
1.6K0
maven中使用springboot返回jsp和json数据
SpringBoot2.0 基础案例(17):自定义启动页,项目打包和指定运行环境
springboot的打包方式有很多种。可以打war包,可以打jar包,可以使用jekins进行打包部署的。不推荐用war包,SpringBoot适合前后端分离,打成jar进行部署更加方便快捷。
知了一笑
2019/07/19
6650
一、如何快速搭建你的第一个SpringBoot项目应用
上次我们说了JavaBean注入的三种方式中基于Java类的配置方式,其实只所以说这种方式,是为了让大家对SpringBoot中的配置文件有一个比较清晰的认识,这样在大家学习起来,不会看的那个懵逼,我把上篇的链接放在下面,如果没看过的同学可以看一下,再接着往下看,可能会更容易理解。
一个程序员的成长
2020/11/25
3210
一、如何快速搭建你的第一个SpringBoot项目应用
推荐阅读
相关推荐
springBoot学习(二)配置环境动态切换和部分注解的运用
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验