spring まとめ

必要なもの
Eclipseオールインワン

MySQL

新規からspringスタータープロジェクト

・Spring Web
・Thymeleaf

・Validation

・Spring Security

・Spring Data JPA

MySQL Driver

Lombok

 

application.propertiesに↓記載

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://ホスト名/データベース名
spring.datasource.username=ユーザ名
spring.datasource.password=パスワード
spring.datasource.sql-script-encoding=utf-8
spring.jpa.database=MYSQL
spring.jpa.hibernate.ddl-auto=none

 

ValidationMessages.propertiesファイルを作成
jakarta.validation.constraints.ヴァリデーション名.message = 警告文

 

-ControllerClass-

RequestMappingでurl毎の処理

 

-Model-

MySQLをSpring Data JPAでつなぐ

EntityClass

ServiceClass

RepositoryInterface (JpaRepositoryをextends)

 

-View-

ThymeleafテンプレートとHTML,CSS,JavaScriptでがんばろ

 

入力内容チェック

Validationで整合性チェック。JavaScriptは送信前に不適切だったら通知する。

 

build.gradle
dependencies {} パッケージ追加時はこの中へ