SpringBoot入门

利用springboot创建一个简单项目

创建简单项目

1.starter 场景启动器:不同的场景启动器维护了所对应的所有的依赖,以简化maven的书写

  • 创建父类:

<parent>
    <groupId>org.springframework.boot</groupId>
    <version>2.3.5.RELEASE</version>
    <artifactId>spring-boot-starter-parent</artifactId>
</parent>
  • web包:
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
  • 打包工具:

部署springboot的插件,只有加了这个插件,当运行 Java -jar xxx.jar才能正常启动

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>2.5.4</version>
        </plugin>
    </plugins>
</build>
  • 启动类:
@SpringBootApplication//标记成Springboot 启动类
public class Application {

    public static void main(String[] args){
        SpringApplication.run(Application.class,args);
    }
}
  • properties:
#设置端口
server.port=8282
    #项目虚拟目录
server.servlet.context-path=/xuexi

1.使用spring initializer新建一个父maven,type选择POM

2.使用spring initializer 新建一个子maven,type选择maven project

修改子项目中的继承方式:

之前:

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.5.4</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

修改后:

 <parent>
        <groupId>com.xuexi02.springboot</groupId>
        <artifactId>spring_boot</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
  • spring_initializer–>springboot_parent–>spring-boot-starter-parent

  • static:保存所有的静态资源;js,css, images;

  • templates:保存所有的模板页面:(Spring Boot 默认jar包使用嵌入式的Tomcat,默认不支持JSP页面);可以使用模板引擎(free marker、thymeleaf)

  • springboot进行懒加载:

spring.main.lazy-initialization=true

自定义SpringApplication

public class SpringbootApplication {

    public static void main(String[] args) {
        SpringApplication app=new SpringApplication(SpringBootApplication.class);
            app.setBannerMode(Banner.Mode.OFF);//可以关闭springboot启动横幅
        app.run( args);
    }

}


  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

已黑化的小白

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值