forked from team-cerezo/spring-boot-postgres-example
-
Notifications
You must be signed in to change notification settings - Fork 0
CRUD機能追加 #1
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
Open
ffujita
wants to merge
7
commits into
master
Choose a base branch
from
develop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
CRUD機能追加 #1
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1453014
プロキシ対策
ffujita 97a92f4
使わないクラスを削除
ffujita babc334
メッセージのid検索、全件検索機能を実装
ffujita 72a2219
messageテーブル作成sqlをflyway管理課に作成
ffujita a918262
全件検索のmethod指定
ffujita 56c347b
メッセージの追加・削除・更新機能を実装
ffujita 3caa3cb
idをURLから取得する
ffujita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| -Dhttp.proxyHost=oskproxy.intra.tis.co.jp | ||
| -Dhttp.proxyPort=8080 | ||
| -Dhttps.proxyHost=oskproxy.intra.tis.co.jp | ||
| -Dhttps.proxyPort=8080 |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.example.message; | ||
|
|
||
| import org.seasar.doma.Entity; | ||
| import org.seasar.doma.GeneratedValue; | ||
| import org.seasar.doma.GenerationType; | ||
| import org.seasar.doma.Id; | ||
|
|
||
| @Entity | ||
| public class Message { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| public long id; | ||
| public String content; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.example.message; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @SpringBootApplication | ||
| @RestController | ||
| @RequestMapping("/message") | ||
| public class MessageApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(MessageApplication.class, args); | ||
| } | ||
|
|
||
| @Autowired | ||
| MessageDao messageDao; | ||
|
|
||
| @GetMapping("/") | ||
| List<Message> all() { | ||
| return messageDao.selectAll(); | ||
| } | ||
|
|
||
| @GetMapping("/{id}") | ||
| Message select(@PathVariable("id") int id) { | ||
| return messageDao.selectById(id); | ||
| } | ||
|
|
||
| @PostMapping("/register") | ||
| void insert(@RequestParam String content) { | ||
| Message message = new Message(); | ||
| message.content = content; | ||
| messageDao.insert(message); | ||
| } | ||
|
|
||
| @PostMapping("/delete") | ||
| void delete(@RequestParam int id) { | ||
| Message message = messageDao.selectById(id); | ||
| messageDao.delete(message); | ||
| } | ||
|
|
||
| @PostMapping("/update/{id}") | ||
| void update(@PathVariable int id, @RequestParam String content) { | ||
| Message message = messageDao.selectById(id); | ||
| message.content = content; | ||
| messageDao.update(message); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.example.message; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import org.seasar.doma.Dao; | ||
| import org.seasar.doma.Delete; | ||
| import org.seasar.doma.Insert; | ||
| import org.seasar.doma.Select; | ||
| import org.seasar.doma.Update; | ||
| import org.seasar.doma.boot.ConfigAutowireable; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @ConfigAutowireable | ||
| @Dao | ||
| public interface MessageDao { | ||
| @Select | ||
| List<Message> selectAll(); | ||
|
|
||
| @Insert | ||
| @Transactional | ||
| int insert(Message message); | ||
|
|
||
| @Select | ||
| Message selectById(int id); | ||
|
|
||
| @Delete | ||
| int delete(Message message); | ||
|
|
||
| @Update | ||
| int update(Message message); | ||
| } |
5 changes: 5 additions & 0 deletions
5
src/main/resources/META-INF/com/example/message/MessageDao/selectAll.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| SELECT | ||
| id, | ||
| content | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. テーブルが持つカラムをすべて取得する場合は 使え!というわけではないけれど、便利です。 |
||
| FROM message | ||
| ORDER BY id ASC | ||
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/com/example/message/MessageDao/selectById.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| SELECT id,content FROM message WHERE id = /* id */0 |
5 changes: 5 additions & 0 deletions
5
src/main/resources/db/migration/V1.2__Create_messages_table.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| CREATE TABLE message ( | ||
| id serial , | ||
| content VARCHAR(100), | ||
| CONSTRAINT "PK" PRIMARY KEY (id) | ||
| ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Springチームはコンストラクタインジェクションを推奨しています。
https://docs.spring.io/spring/docs/5.1.4.RELEASE/spring-framework-reference/core.html#beans-constructor-vs-setter-injection
私もコンストラクタインジェクションの方が好き。
理由は次の通り。
finalにできるnullでないことを保証できるコード例: