feat(project): 初始化项目基础结构和配置

- 添加 .gitattributes 和 .gitignore 文件以管理版本控制行为- 配置 Spring Boot 应用程序的基本设置,包括数据源和 JPA 设置
- 添加启动 banner 提升应用识别度
- 引入 Maven Wrapper 简化构建环境配置
- 创建基础实体类 UserEntity 并配置相关字段及约束
- 初始化主应用程序入口点和测试类确保可运行性
This commit is contained in:
hanserwei
2025-10-21 16:40:26 +08:00
commit fff8f46dcf
10 changed files with 527 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.hanserwei.snailsai;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SnailsAiApplication {
public static void main(String[] args) {
SpringApplication.run(SnailsAiApplication.class, args);
}
}

View File

@@ -0,0 +1,53 @@
package com.hanserwei.snailsai.entity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serial;
import java.io.Serializable;
@Entity
@Table(
name = "users",
uniqueConstraints = @UniqueConstraint(
name = "UQ_USER_NAME",
columnNames = {"user_name"} // 指定应用约束的列
)
)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class UserEntity implements Serializable {
@Serial
private static final long serialVersionUID = 812305521669146765L;
// 1. 主键自增ID
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
// 2. 用户名:不能为空,长度限制
@Column(name = "user_name", nullable = false, unique = true, length = 50)
private String username;
// 3. 密码:加密存储,不能为空,长度需足够长
@Column(name = "password", nullable = false, length = 100)
private String password;
// 4. 逻辑外键
@Column(name = "hobby_id")
private Long hobbyId;
// 5. 补充审计字段 (推荐)
@Column(name = "create_time", nullable = false)
private java.time.LocalDateTime createTime;
@Column(name = "update_time")
private java.time.LocalDateTime updateTime;
}

View File

@@ -0,0 +1,30 @@
#file: noinspection SpringBootConfigYamlInspection
spring:
application:
name: snails-ai
banner:
location: config/banner.txt
jpa:
hibernate:
ddl-auto: update
properties:
# 开启 SQL 语句格式化 (重点:让 SQL 易读)
hibernate.format_sql: true
# 开启 SQL 语法高亮 (重点:让 SQL 醒目)
hibernate.highlight_sql: true
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/snails_ai?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowMultiQueries=true&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: mysql
# HikariCP 连接池配置
hikari:
maximum-pool-size: 20 # 最大连接数设置为 20
minimum-idle: 20 # 保持 20 个空闲连接(与最大连接数一致)
connection-timeout: 5000 # 获取连接超时 5 秒
max-lifetime: 28800000 # 8 小时(确保在数据库连接超时前被回收)
logging:
level:
org.hibernate.SQL: debug
# 隐藏掉 Hibernate 冗长的连接池 INFO 信息
org.hibernate.orm.connections.pooling: WARN

View File

@@ -0,0 +1,11 @@
___ ___ ___ ___ ___ ___
/\ \ /\__\ /\ \ ___ /\__\ /\ \ /\ \ ___
/::\ \ /::| | /::\ \ /\ \ /:/ / /::\ \ /::\ \ /\ \
/:/\ \ \ /:|:| | /:/\:\ \ \:\ \ /:/ / /:/\ \ \ /:/\:\ \ \:\ \
_\:\~\ \ \ /:/|:| |__ /::\~\:\ \ /::\__\ /:/ / _\:\~\ \ \ /::\~\:\ \ /::\__\
/\ \:\ \ \__\ /:/ |:| /\__\ /:/\:\ \:\__\ __/:/\/__/ /:/__/ /\ \:\ \ \__\ /:/\:\ \:\__\ __/:/\/__/
\:\ \:\ \/__/ \/__|:|/:/ / \/__\:\/:/ / /\/:/ / \:\ \ \:\ \:\ \/__/ \/__\:\/:/ / /\/:/ /
\:\ \:\__\ |:/:/ / \::/ / \::/__/ \:\ \ \:\ \:\__\ \::/ / \::/__/
\:\/:/ / |::/ / /:/ / \:\__\ \:\ \ \:\/:/ / /:/ / \:\__\
\::/ / /:/ / /:/ / \/__/ \:\__\ \::/ / /:/ / \/__/
\/__/ \/__/ \/__/ \/__/ \/__/ \/__/

View File

@@ -0,0 +1,13 @@
package com.hanserwei.snailsai;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class SnailsAiApplicationTests {
@Test
void contextLoads() {
}
}