mirror of
https://gitee.com/many2many/java-web.git
synced 2025-01-11 22:50:54 +08:00
Compare commits
No commits in common. "bb6867d6d6cf67363786ce65218b29e10ab8c034" and "b40eae61d34775032667482be48655553a945f77" have entirely different histories.
bb6867d6d6
...
b40eae61d3
@ -7,75 +7,17 @@
|
||||
|
||||
#### 7.1.1 Git仓库
|
||||
|
||||
- 创建远程项目仓库
|
||||
在http://123.249.84.124:8066/ 注册账号
|
||||
|
||||
在http://123.249.84.124:8066/ 注册账号 , 创建仓库paopao
|
||||
|
||||
> 选择.gitignore文件模板: java
|
||||
|
||||
> 设置分支模型: 单分支模型,分支名:master
|
||||
|
||||
- 在idea中clone项目
|
||||
|
||||
idea的菜单`file -> new -> project from version control -> Repository URL`,url输入框中输入项目的远程仓库地址,点击`clone`。
|
||||
创建仓库 paopao
|
||||
|
||||
#### 7.1.2 初始化spring boot项目
|
||||
|
||||
#### 使用 Spring Initializr 创建项目
|
||||
- 访问 [Spring Initializr](https://start.spring.io/)
|
||||
- 选择以下选项:
|
||||
- **Project:** Gradle-Groovy
|
||||
- **Language:** Java
|
||||
- **Spring Boot:** 选择最新稳定版本
|
||||
- **Group:** 输入你的组织名称(例如 `com.lk`)
|
||||
- **Artifact:** 输入项目名称(例如 `paopao`)
|
||||
- **Name:** 项目名称(默认与 Artifact 相同)
|
||||
- **Package name:** 包名(默认与 Group 和 Artifact 相同)
|
||||
- **Packaging:** Jar
|
||||
- **Java Version:** 选择合适的 Java 版本(17或21)
|
||||
- 添加以下依赖:
|
||||
- **Web**
|
||||
- **JPA**
|
||||
- **H2 Database**
|
||||
|
||||
- 点击 `Generate` 按钮,下载生成的项目压缩包。
|
||||
|
||||
#### 解压并复制文件
|
||||
- 将下载的压缩包解压到一个临时目录。
|
||||
- 将解压后的目录中的所有文件复制到你的本地项目根目录下。
|
||||
- 确保 `build.gradle` 等文件位于项目根目录下。
|
||||
|
||||
#### 在 IDEA 中设置项目
|
||||
a. **打开项目**
|
||||
- 打开 IntelliJ IDEA。
|
||||
- 选择 `File` -> `Open`,选择你的项目根目录,然后点击 `OK`。
|
||||
|
||||
b. **设置项目使用的 JDK**
|
||||
- 打开 `File` -> `Project Structure`。
|
||||
- 在 `Project` 标签页中,选择 `Project SDK`,选择你安装的 JDK 或者下载JDK再选择。
|
||||
|
||||
c. **配置 Gradle 使用的 JVM 版本**
|
||||
- 打开 `File` -> `Settings`(或按 `Ctrl+Alt+S`)。
|
||||
- 导航到 `Build, Execution, Deployment` -> `Build Tools` -> `Gradle`。
|
||||
- 在 `Gradle JVM` 下拉菜单中,选择你安装的 JDK 版本, 保持使用的版本和项目jdk版本一致。(如果看不到此项,尝试下面的步骤d,重新导入项目)
|
||||
|
||||
d. **导入项目**
|
||||
- 如果项目没有自动导入,可以手动导入:
|
||||
- 打开 `File` -> `New` -> `Module from Existing Sources`。
|
||||
- 选择项目根目录下的 `build.gradle` 文件,然后按照提示完成导入。
|
||||
|
||||
完成以上步骤后,应该能在idea的右侧插件栏中看到gradle的图标。
|
||||
https://start.spring.io/ 创建项目
|
||||
|
||||
#### 7.1.3 gradle配置
|
||||
|
||||
项目中的gradle/wrapper/gradle-wrapper.properties 文件中,将下载的gradle地址修改为使用国内源。
|
||||
|
||||
```properties
|
||||
distributionUrl=https://mirrors.cloud.tencent.com/gradle/gradle-8.5-bin.zip
|
||||
```
|
||||
|
||||
项目中build.gradle 文件中,设置使用国内maven服务器,添加如下配置:
|
||||
|
||||
国内源配置
|
||||
```groovy
|
||||
repositories {
|
||||
mavenLocal()
|
||||
@ -85,92 +27,28 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
```
|
||||
项目中build.gradle 文件中,修改h2数据库的依赖,指定版本号,使用H2 V2(为了使用数据库工具dbeaver时比较方便设置):
|
||||
|
||||
H2 V2的JDBC驱动依赖:
|
||||
```groovy
|
||||
runtimeOnly 'com.h2database:h2:2.1.214'
|
||||
```
|
||||
|
||||
修改完成后,刷新gradle, 等待gradle下载依赖。
|
||||
|
||||
下载完成,在gradle插件的窗口中,运行`tasks`,选择`bootRun`任务。项目应能正常运行。
|
||||
|
||||
在idea中使用git菜单,将项目所有更新提交到远程仓库.
|
||||
|
||||
|
||||
#### 7.1.4 ui部署
|
||||
|
||||
nginx中部署 [paopao-web-ui.zip](../examples/chapter07/paopao-web-ui.zip)
|
||||
|
||||
- 安装nginx
|
||||
|
||||
下载nginx: https://nginx.org/download/nginx-1.26.2.zip
|
||||
|
||||
解压zip包,在解压后的目录下,运行nginx.exe, 即可启动nginx服务。
|
||||
|
||||
在浏览器中访问:http://localhost 应能看到nginx的欢迎界面。
|
||||
|
||||
- 发布前端代码
|
||||
|
||||
前端代码压缩文件`paopao-web-ui.zip`解压, 将前端代码根目录下的所有文件拷贝到html目录下,重启nginx服务。
|
||||
|
||||
浏览器访问:http://localhost/index.html
|
||||
|
||||
[Spring Boot处理CORS跨域请求的三种方法](https://cloud.tencent.com/developer/article/1655583)
|
||||
|
||||
### 7.2 用户注册功能开发
|
||||
|
||||
基本上按照层次结构创建系统的包结构, 在`com.lk.paopao`包下创建子包`controllers`、`services`、`entities`、`repositories`。
|
||||
|
||||
|
||||
#### 7.2.1 API设计
|
||||
|
||||
[用户注册API.md](./resources/用户注册API.md)
|
||||
|
||||
#### 7.2.2 spring boot配置文件修改
|
||||
|
||||
在项目目录`src/main/resources`下,新建application.yml文件,添加数据库相关配置:
|
||||
|
||||
```yaml
|
||||
|
||||
spring:
|
||||
jackson:
|
||||
property-naming-strategy: SNAKE_CASE # 驼峰转下划线,以适应数据库字段命名规则
|
||||
datasource:
|
||||
url: jdbc:h2:file:./db.h2 # 使用文件存储,配置数据库连接URL
|
||||
driverClassName: org.h2.Driver # 指定数据库驱动类
|
||||
username: root # 数据库用户名
|
||||
password: root # 数据库密码
|
||||
h2:
|
||||
console: # 开启console访问 默认false,提供数据库管理界面
|
||||
enabled: true # 启用H2控制台访问功能
|
||||
settings:
|
||||
trace: true # 开启h2 console 跟踪 方便调试 默认 false
|
||||
web-allow-others: true # 允许console 远程访问 默认false,提高可用性
|
||||
path: /h2 # h2 访问路径上下文,定义访问路由
|
||||
jpa:
|
||||
show-sql: true # 显示SQL查询,便于调试和性能优化
|
||||
open-in-view: false # 禁用Open SessionInView,避免性能问题和资源泄露
|
||||
defer-datasource-initialization: true # 延迟数据源初始化,确保配置加载完成
|
||||
database-platform: org.hibernate.dialect.H2Dialect # 指定数据库方言,优化SQL生成
|
||||
hibernate:
|
||||
ddl-auto: update # 自动更新数据库结构,适应实体模型变化
|
||||
|
||||
```
|
||||
yml配置文件的格式需要注意:缩进和空格是敏感的,需要严格遵循格式。
|
||||
|
||||
#### 7.2.3 实体类和Repository接口
|
||||
|
||||
设计和实现实体类User
|
||||
|
||||
|
||||
|
||||
对应的数据库接口: UserRepository
|
||||
|
||||
|
||||
|
||||
#### 7.2.3 Controller和service
|
||||
|
||||
#### 7.2.4 解决跨域问题
|
||||
#### 7.2.4 测试
|
||||
|
||||
### 7.3 发布文章功能开发
|
||||
|
||||
|
@ -1,84 +0,0 @@
|
||||
## 1. 用户注册
|
||||
|
||||
### 1.1 接口描述
|
||||
用户输入账号、邮箱、密码完成注册。
|
||||
### 1.2 请求URL
|
||||
`/v1/auth/register`
|
||||
|
||||
### 1.3 请求方式
|
||||
**POST**
|
||||
|
||||
### 1.4 请求头
|
||||
| 头字段 | 必填 | 数据类型 | 描述 |
|
||||
| ------------ | ---- | ------------- | -------------------------------- |
|
||||
| Content-Type | 是 | application/json | 指定请求体的媒体类型为JSON |
|
||||
|
||||
### 1.5 请求体参数
|
||||
| 参数名称 | 必填 | 数据类型 | 约束条件 | 描述 | 示例 | 允许空值 |
|
||||
|-----------| ---- | -------- | -------- | ---------------------------- | ------------ | -------- |
|
||||
| username | 是 | 字符串 | 1-50字符 | 用于登录的账号(手机号或邮箱) | "user123" | 否 |
|
||||
| password | 是 | 字符串 | 1-50字符 | 密码 | "p@ssw0rd" | 否 |
|
||||
|
||||
|
||||
### 1.6 请求示例
|
||||
```http
|
||||
POST /v1/auth/register
|
||||
Host: {apiAddress}
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"username": "a123",
|
||||
"password": "123456"
|
||||
}
|
||||
```
|
||||
|
||||
### 1.7 返回参数说明
|
||||
| 参数名称 | 必填 | 数据类型 | 约束条件 | 描述 |
|
||||
|------| ---- | -------- | -- |-----------|
|
||||
| code | 是 | 整型 | | 错误码,0表示成功 |
|
||||
| msg | 否 | 字符串 | | 错误信息描述 |
|
||||
| data | 否 | json | | 具体业务数据 |
|
||||
|
||||
data结构说明:
|
||||
|
||||
| 参数名称 | 必填 | 数据类型 | 约束条件 | 描述 |
|
||||
|-----------| ---- | -------- |--------| ---------------------------- |
|
||||
| id | 是 | 整型 | | 用户id |
|
||||
| username | 是 | 字符串 | 1-32字符 | 登录账号|
|
||||
|
||||
|
||||
|
||||
### 1.8 响应示例(成功)
|
||||
|
||||
```json
|
||||
{"code":0,"msg":"success","data":{"id":100067,"username":"a123"}}
|
||||
```
|
||||
### 1.9 响应示例(错误)
|
||||
```json
|
||||
{ "code": 409, "msg": "用户名存在" }
|
||||
```
|
||||
|
||||
### 1.10 错误响应码参考
|
||||
更多响应错误码及含义,请参阅[API响应码表](URL/for/api/responseCode/table)。
|
||||
|
||||
### 1.11 安全性与认证
|
||||
|
||||
|
||||
### 1.12 测试环境
|
||||
访问测试环境以进行接口调试:
|
||||
[https://test.apiAddress.com](https://test.apiAddress.com)
|
||||
|
||||
### 1.13 版本管理
|
||||
本API通过URI路径进行版本控制。请在请求URL中包含`/v1`以使用当前版本。
|
||||
|
||||
### 1.14 更新记录
|
||||
- **2024-05-07**:添加data结构说明
|
||||
- **2024-04-29**:发布文档初始版本。
|
||||
|
||||
|
||||
### 1.15 联系支持
|
||||
如需帮助或对API有任何疑问,请通过电子邮件与我们联系:[support@api.com](mailto:support@api.com)。
|
||||
|
||||
### 1.16 反馈与建议
|
||||
发现文档问题或有改进建议?请填写[反馈表单](https://forms.api.com/feedback)与我们分享。
|
||||
|
3
examples/chapter07/paopao/.gitattributes
vendored
3
examples/chapter07/paopao/.gitattributes
vendored
@ -1,3 +0,0 @@
|
||||
/gradlew text eol=lf
|
||||
*.bat text eol=crlf
|
||||
*.jar binary
|
37
examples/chapter07/paopao/.gitignore
vendored
37
examples/chapter07/paopao/.gitignore
vendored
@ -1,37 +0,0 @@
|
||||
HELP.md
|
||||
.gradle
|
||||
build/
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
@ -1,44 +0,0 @@
|
||||
# Paopao
|
||||
|
||||
This app was created with Bootify.io - tips on working with the code [can be found here](https://bootify.io/next-steps/).
|
||||
Feel free to contact us for further questions.
|
||||
|
||||
## Development
|
||||
|
||||
Update your local database connection in `application.yml` or create your own `application-local.yml` file to override
|
||||
settings for development.
|
||||
|
||||
During development it is recommended to use the profile `local`. In IntelliJ `-Dspring.profiles.active=local` can be
|
||||
added in the VM options of the Run Configuration after enabling this property in "Modify options".
|
||||
|
||||
Lombok must be supported by your IDE. For IntelliJ install the Lombok plugin and enable annotation processing -
|
||||
[learn more](https://bootify.io/next-steps/spring-boot-with-lombok.html).
|
||||
|
||||
After starting the application it is accessible under `localhost:8080`.
|
||||
|
||||
## Build
|
||||
|
||||
The application can be built using the following command:
|
||||
|
||||
```
|
||||
gradlew clean build
|
||||
```
|
||||
|
||||
Start your application with the following command - here with the profile `production`:
|
||||
|
||||
```
|
||||
java -Dspring.profiles.active=production -jar ./build/libs/paopao-0.0.1-SNAPSHOT.jar
|
||||
```
|
||||
|
||||
If required, a Docker image can be created with the Spring Boot plugin. Add `SPRING_PROFILES_ACTIVE=production` as
|
||||
environment variable when running the container.
|
||||
|
||||
```
|
||||
gradlew bootBuildImage --imageName=com.lk/paopao
|
||||
```
|
||||
|
||||
## Further readings
|
||||
|
||||
* [Gradle user manual](https://docs.gradle.org/)
|
||||
* [Spring Boot reference](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/)
|
||||
* [Spring Data JPA reference](https://docs.spring.io/spring-data/jpa/reference/jpa.html)
|
@ -1,34 +0,0 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot' version '3.3.5'
|
||||
id 'io.spring.dependency-management' version '1.1.6'
|
||||
}
|
||||
|
||||
group = 'com.lk'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(17)
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
maven { url 'https://mirrors.cloud.tencent.com/nexus/repository/maven-public/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/central' }
|
||||
maven { url 'https://maven.aliyun.com/repository/public' }
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
runtimeOnly 'com.h2database:h2:2.1.214'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
||||
}
|
||||
|
||||
tasks.named('test') {
|
||||
useJUnitPlatform()
|
||||
}
|
Binary file not shown.
@ -1,7 +0,0 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https://mirrors.cloud.tencent.com/gradle/gradle-8.5-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
252
examples/chapter07/paopao/gradlew
vendored
252
examples/chapter07/paopao/gradlew
vendored
@ -1,252 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
# This is normally unused
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||
' "$PWD" ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
if ! command -v java >/dev/null 2>&1
|
||||
then
|
||||
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||
# shellcheck disable=SC2039,SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
94
examples/chapter07/paopao/gradlew.bat
vendored
94
examples/chapter07/paopao/gradlew.bat
vendored
@ -1,94 +0,0 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
@rem This is normally unused
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
@ -1 +0,0 @@
|
||||
rootProject.name = 'paopao'
|
@ -1,13 +0,0 @@
|
||||
package com.lk.paopao;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class PaopaoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(PaopaoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.lk.paopao.conf;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 配置类,用于设置跨域请求
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
/**
|
||||
* 创建并配置CorsFilter bean
|
||||
*
|
||||
* @return CorsFilter bean实例,用于处理跨域请求
|
||||
*/
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
// 创建URL基于的Cors配置源
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
// 创建Cors配置实例
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
|
||||
// 配置允许的源
|
||||
config.setAllowedOrigins(List.of("http://localhost"));
|
||||
// 配置允许的方法
|
||||
config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE"));
|
||||
// 配置允许的头部
|
||||
config.setAllowedHeaders(List.of("*"));
|
||||
// 允许凭据
|
||||
config.setAllowCredentials(true);
|
||||
|
||||
// 在配置源中注册全局跨域配置
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
// 返回CorsFilter实例
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
}
|
@ -1 +0,0 @@
|
||||
spring.application.name=paopao
|
@ -1,13 +0,0 @@
|
||||
package com.lk.paopao;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class PaopaoApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user