springboot 1 介绍新建springboot项目

SpringBoot 目的是简化Spring应用的初始搭建和开发过程。

特点
  • 创建独立的额spring应用程序
  • 内嵌tomcat 不用配置war文件
  • 简化Maven的配置(可以做到无xml配置)
  • 自动配置Spring
  • 提供生产就绪功能
用idea搭建springboot环境 web下
  1. 点击新建项目,如下图, 点击next
    在这里插入图片描述
  2. 输入分组和名字,点击next在这里插入图片描述
  3. 选择这三个依赖,选择next
    在这里插入图片描述
  4. 输入项目名和路径 就可建立起来在这里插入图片描述
  5. 结果:
    在这里插入图片描述
springboot的代码结构
代码层的结构

根目录:com.springboot

  1. 工程启动类(ApplicationServer.java)置于com.springboot.build包下
  2. 实体类(domain)置于com.springboot.domain
  3. 数据访问层(Dao)置于com.springboot.repository
  4. 数据服务层(Service)置于com,springboot.service,数据服务的实现接口(serviceImpl)至于com.springboot.service.impl
  5. 前端控制器(Controller)置于com.springboot.controller
  6. 工具类(utils)置于com.springboot.utils
  7. 常量接口类(constant)置于com.springboot.constant
  8. 配置信息类(config)置于com.springboot.config
  9. 数据传输类(vo)置于com.springboot.vo
资源文件的结构

根目录:src/main/resources

  1. 配置文件(.properties/.json等)置于config文件夹下
  2. spring.xml置于META-INF/spring文件夹下
  3. 页面以及js/css/image等置于static文件夹下的各自文件下
  4. templates:放置网页,页面
  5. application.properties 文件是配置文件

Springboot将很多的配置文件进行了统一的管理。并且配置了默认值。(有默认值 记住默认值并配置即可)
springboot会自动寻找并运用配置,(找的是application.properties 和 application.yml),否则使用默认配置
两种配置文件的区别:

application.properties
server.prot = 8080
application.yml
server:
	port:8080

.properties 优先级高于 .yml 文件

springboot的入口类
@SpringBootApplication
public class SpringbootdemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(SpringbootdemoApplication.class, args);
    }

}

@SpringBootApplication 是一个组合的注解,包含有

  • @EnableAutoConfiguration
  • @ComponentScan
  • @SpringBootConfiguration
    三个注解,springboot会扫描这个类路径下的所有包
pom文件基本的配置
<?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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>springbootdemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springbootdemo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.0</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
  • spring-boot-starter-parent : 用于提供Maven默认依赖
  • spring-boot-starter-web : 提供web服务
  • spring-boot-starter-test:和测试相关的包
  • spring-boot-maven-plugin:maven的插件,为springboot提供maven操作,打包等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值