Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Answer #1

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 14 additions & 58 deletions ANSWER.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,18 @@
# Spring Boot基础
# Spring Data Jpa

## 练习描述
- 使用Spring boot来完成一个关于Employee的API接口
- 至少需要完成对所有Employee的一个Get请求,返回一个包含所有Employee的JSON,接口路径范例:`http://localhost:8080/employee`
- 有余力的同学可以尝试完成对Employee的`CURD(增删改查)`全部接口
### 如何下载
- 答案详情请点击上方 作业答案下载,来下载 answer.zip 压缩包文件

## 环境描述
- java8
- spring-boot
- Intellij-IDEA
### 如何启动
- 解压 `answer.zip`,用 IntelliJ IDE 打开
- 首先本地启动`MySQL server`
- 项目根目录下运行 `./gradlew test`,所有测试均可通过

## 如何开始
- 使用如下方式建立Spring boot项目
- 从`http://start.spring.io/`生成一个项目包,并下载下来,解压,开始编码
- 使用`./gradlew bootRun`来启动服务器
### 注意事项

## 输出规范
- 仔细阅读上面的练习描述,完成作业
- 运行项目,启动服务器
- 使用`Postman`来向目标URL发送请求,获取Response,Response JSON格式如下:
```json
[
{
"id": 0,
"name": "小明",
"age": 20,
"gender": "男"
},
{
"id": 1,
"name": "小红",
"age": 19,
"gender": "女"
},
{
"id": 2,
"name": "小智",
"age": 15,
"gender": "男"
},
{
"id": 3,
"name": "小刚",
"age": 16,
"gender": "男"
},
{
"id": 4,
"name": "小霞",
"age": 15,
"gender": "女"
}
]
```
- 截图,并将图片存放在项目根目录下,截图命名为`result.png`,图片中Response中的Employee必须包括你自己的名字,例如:
![](https://raw.githubusercontent.com/tws-online-quiz/spring-boot-quiz/master/example.png)

## 题目要求
- 至少完成`Get`请求
- 代码通过小步提交,并且每次提交的描述都要有意义
- 使用快捷键编码
- 请不要修改项目中mysql的用户名密码,否则测试不通过

### 重点讲解
- 建议按照教程首先完成`entity`的创建
- 按照 `TDD` 方式开发
- 实现在 `repository` 中,并配有部分讲解
3 changes: 2 additions & 1 deletion spring-data-jpa-quiz.iml → Spring-Data-JPA-Quiz.iml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="spring-data-jpa-quiz" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" relativePaths="true" type="JAVA_MODULE" version="4">
<module external.linked.project.id="Spring-Data-JPA-Quiz" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" relativePaths="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/out" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
25 changes: 25 additions & 0 deletions Spring-Data-JPA-Quiz_main.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="Spring-Data-JPA-Quiz:main" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration />
</facet>
<facet type="web" name="Web Gradle : Spring-Data-JPA-Quiz.war">
<configuration>
<webroots>
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
</webroots>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/out/production/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$/src/main">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
19 changes: 19 additions & 0 deletions Spring-Data-JPA-Quiz_test.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="Spring-Data-JPA-Quiz:test" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration />
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output-test url="file://$MODULE_DIR$/out/test/classes" />
<exclude-output />
<content url="file://$MODULE_DIR$/src/test">
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestModuleProperties" production-module="Spring-Data-JPA-Quiz_main" />
</module>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildscript {
springBootVersion = '2.0.0.RELEASE'
}
repositories {
mavenCentral()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
Expand All @@ -17,7 +17,7 @@ apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'

repositories {
mavenCentral()
mavenCentral()
}

configurations {
Expand Down
1 change: 1 addition & 0 deletions database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create database employee_db;
4 changes: 4 additions & 0 deletions script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
service mysql start
mysql -uroot -proot -e "source ./database.sql"
./gradlew test
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

rootProject.name = 'backend'
Loading