Skip to content

CRUD機能追加#1

Open
ffujita wants to merge 7 commits into
masterfrom
develop
Open

CRUD機能追加#1
ffujita wants to merge 7 commits into
masterfrom
develop

Conversation

@ffujita
Copy link
Copy Markdown
Owner

@ffujita ffujita commented Feb 1, 2019

No description provided.

}

@Autowired
MessageDao messageDao;
Copy link
Copy Markdown

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 でないことを保証できる
  • コンストラクタで依存クラスを設定できるので、Spring管理下ではなく単なるクラスとしてテストが書ける

コード例:

final MessageDao messageDao;

public MessageApplication(MessageDao messageDao) {
    this.messageDao = Objects.requireNonNull(messageDao);
}

@@ -0,0 +1,5 @@
SELECT
id,
content
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テーブルが持つカラムをすべて取得する場合は expand が使えます。
https://doma.readthedocs.io/en/stable/sql/#expand

使え!というわけではないけれど、便利です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants