springboot_项目结构_数据库

TOMCAT项目结构

springboot_项目结构_数据库

<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    id="WebApp_ID" version="3.1">
<display-name></display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index1.jsp</welcome-file>
</welcome-file-list
<servlet>
    <servlet-name>servlet1</servlet-name>
    <servlet-class>net.test.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>servlet1</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>

Springboot WAR项目结构

    <packaging>war</packaging>    
<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>demo</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
@SpringBootApplication
public class Main {  //1.继承SpringBootServletInitializer
    public static void main(String[] args) {
        SpringApplication.run(Main.class,args);
    }
}

class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Main.class);
    }
}

注意:使用tomcat10总是访问不到controller,不知道什么原因

war目录结构

  1. META-INF
    1. maven
    2. MANIFEST.MF
    3. war-tracker
  2. org
    1. springframework
      1. boot
        1. loader
          1. xxx
          2. yyy
          3. zzz
  3. WEB-INF
    1. classes
      1. com.example
        1. Main.class
    2. lib
    3. lib-provide
    4. layers.idx

Springboot JAR项目结构

外部配置文件位置

/home/project

  1. xxx.jar
  2. application.yml
  3. config/application.yml
目录结构
  1. BOOT-INF
    1. classes
      1. com.example
        1. Main.class
      2. static
      3. templates
      4. application.yml
      5. config/application.yml
    2. lib
    3. classpath,idx
    4. layer.idx
  2. META-INF:同上
  3. org:同上

Flyway

<dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>5.0.3</version>
</dependency>
<plugin>
                <groupId>org.flywaydb</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>5.0.3</version>
</plugin>
flyway.sql-migration-prefix=指定前缀
flyway.baseline-description对执行迁移时基准版本的描述.
flyway.baseline-on-migrate当迁移时发现目标schema非空,而且带有没有元数据的表时,是否自动执行基准迁移,默认false.
flyway.baseline-version开始执行基准迁移时对现有的schema的版本打标签,默认值为1.
flyway.check-location检查迁移脚本的位置是否存在,默认false.
flyway.clean-on-validation-error当发现校验错误时是否自动调用clean,默认false.
flyway.enabled是否开启flywary,默认true.
flyway.encoding设置迁移时的编码,默认UTF-8.
flyway.ignore-failed-future-migration当读取元数据表时是否忽略错误的迁移,默认false.
flyway.init-sqls当初始化好连接时要执行的SQL.
flyway.locations迁移脚本的位置,默认db/migration.
flyway.out-of-order是否允许无序的迁移,默认false.
flyway.password目标数据库的密码.
flyway.placeholder-prefix设置每个placeholder的前缀,默认${.
flyway.placeholder-replacementplaceholders是否要被替换,默认true.
flyway.placeholder-suffix设置每个placeholder的后缀,默认}.
flyway.placeholders.[placeholder name]设置placeholder的value
flyway.schemas设定需要flywary迁移的schema,大小写敏感,默认为连接默认的schema.
flyway.sql-migration-prefix迁移文件的前缀,默认为V.
flyway.sql-migration-separator迁移脚本的文件名分隔符,默认__
flyway.sql-migration-suffix迁移脚本的后缀,默认为.sql
flyway.tableflyway使用的元数据表名,默认为schema_version
flyway.target迁移时使用的目标版本,默认为latest version
flyway.url迁移时使用的JDBC URL,如果没有指定的话,将使用配置的主数据源
flyway.user迁移数据库的用户名
flyway.validate-on-migrate迁移时是否校验,默认为true.
# 在classpath下新建/db/migration文件夹,并创建sql脚本文件:

liquibase

<dependency>
  <groupId>org.liquibase</groupId>
  <artifactId>liquibase-core</artifactId>
</dependency>
@Bean
  public SpringLiquibase liquibase(DataSource dataSource) {
    SpringLiquibase liquibase = new SpringLiquibase();
    liquibase.setDataSource(dataSource);
    //指定changelog的位置,这里使用的一个master文件引用其他文件的方式
    liquibase.setChangeLog("classpath:liquibase/master.xml");
    liquibase.setContexts("development,test,production");
    liquibase.setShouldRun(true);
    return liquibase;
  }

# /resources/liquibase/master.xml
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">

    <includeAll path="liquibase/changelogs/" relativeToChangelogFile="false"/>

</databaseChangeLog>
# 数据库表生成
# /resources/liquibase/changelog-1.0.xml
# 方法一引入sql
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
    <include file="liquibase/changelogs/project.sql" relativeToChangelogFile="false"/>
</databaseChangeLog>
# 方法二直接写
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
         http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">

    <changeSet id="20190713-01" author="solo">
        <createTable tableName="project_info">
            <column name="project_id" type="varchar(64)" encoding="utf8" remarks="项目id">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="project_name" type="varchar(255)" encoding="utf8" remarks="项目名字"/>
            <column name="project_difficulty" type="float" encoding="utf8" remarks="项目难度"/>
            <column name="category_id" type="varchar(64)" encoding="utf8" remarks="项目类型类目编号"/>
            <column name="project_status" type="int(11)" encoding="utf8" remarks="项目状态, 0招募中,1 进行中,2已完成,3失败,4延期,5删除"/>
            <column name="project_desc" type="varchar(512)" encoding="utf8" remarks="项目简介"/>
            <column name="project_creater_id" type="varchar(64)" encoding="utf8" remarks="项目创建者id"/>
            <column name="team_id" type="varchar(64)" encoding="utf8" remarks="项目所属团队id"/>
            <column name="create_time" type="bigint(64)" encoding="utf8" remarks="创建时间"/>
            <column name="update_time" type="bigint(64)" encoding="utf8" remarks="更新时间"/>
        </createTable>
    </changeSet>
    
    <changeSet id="20190713-02" author="solo">
        <createTable tableName="project_category" remarks="项目类型表">
            <column name="id" type="varchar(64)" remarks="项目类型id">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="name" type="varchar(255)" remarks="类目类型名称"/>
            <column name="status" type="int(11)" remarks="状态。1正常,2删除"/>
            <column name="remark" type="varchar(255)" remarks="备注"/>
        </createTable>
    </changeSet>

    <changeSet id="20190713-03" author="solo">
        <createTable tableName="project_like_user" remarks="项目点赞表">
            <column name="id" type="varchar(64)" remarks="主键id">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="project_id" type="varchar(64)" remarks="项目id"/>
            <column name="user_id" type="varchar(64)" remarks="点赞的用户id"/>
            <column name="status" type="int(11)" remarks="点赞状态,0 取消点赞,1点赞"/>
            <column name="type" type="int(11)" remarks="类型 1点赞"/>
            <column name="create_time" type="bigint(64)" remarks="创建时间"/>
            <column name="update_time" type="bigint(64)" remarks="更新时间"/>
        </createTable>
    </changeSet>

    <changeSet id="20190713-04" author="solo">
        <createTable tableName="project_picture" remarks="项目图片表">
            <column name="id" type="varchar(64)" remarks="图片id">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="project_id" type="varchar(64)" remarks="项目id"/>
            <column name="picture_url" type="varchar(64)" remarks="图片地址"/>
            <column name="picture_url_32" type="varchar(64)" remarks="图片地址32位"/>
            <column name="picture_url_64" type="varchar(64)" remarks="图片地址64位"/>
        </createTable>
    </changeSet>

</databaseChangeLog>

springboot_项目结构_数据库

上一篇:C++计算器代码


下一篇:C++封装常用对象和对头文件以及预编译机制的探索