質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

Q&A

解決済

1回答

644閲覧

リレーション関係のスキーマを一度の入力欄で一括INSERTするためには

Ta-Jn

総合スコア11

MySQL

MySQL(マイエスキューエル)は、TCX DataKonsultAB社などが開発するRDBMS(リレーショナルデータベースの管理システム)です。世界で最も人気の高いシステムで、オープンソースで開発されています。MySQLデータベースサーバは、高速性と信頼性があり、Linux、UNIX、Windowsなどの複数のプラットフォームで動作することができます。

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Spring Boot

Spring Bootは、Javaのフレームワークの一つ。Springプロジェクトが提供する様々なフレームワークを統合した、アプリケーションを高速で開発するために設計されたフレームワークです。

0グッド

0クリップ

投稿2020/06/04 08:45

編集2020/06/04 09:12

Spring JPAを使ったプログラムでリレーション関係の2つのスキーマに一括INSERTを
やりたいのですが、うまくいかず。

UserServiceでそれぞれの入力項目をそれぞれのオブジェクトに格納し
saveでそれぞれのスキーマに入力する予定でした。

ネットを漁って2日が立ちますが、全くわからないので
手法やサイトのリンクを教えていただければ幸いです。

@Controller public class UserController { /** * ユーザー情報 Service */ @Autowired UserService userService; /** * ユーザー新規登録画面を表示 * @param model Model * @return ユーザー情報一覧画面 */ @RequestMapping(value = "/user/add", method = RequestMethod.GET) public String displayAdd(Model model) { model.addAttribute("userRequest", new UserRequest()); return "user/add"; }   @RequestMapping(value="/user/create", method=RequestMethod.POST) public String create(@ModelAttribute UserRequest userRequest, Model model) { // ユーザー情報の登録 userService.create(userRequest); return "redirect:/user/list"; } }
@Data public class UserRequest implements Serializable { /** * 契約ID */ private String contractId; /** * 会社名 */ private String company; /** * 店舗名 */ private String storeName; /** * フリガナ */ private String furigana; /** * 導入経路 */ private String route; /** * アカウント発行日 */ private String account; /** * 支払い開始日 */ private String payStart; /** * プランID */ private String planId; /** * 請求ID */ private String billingId; /** * 請求方法 */ private String billingMethod; /** * 請求年月 */ private String billingData; /** * プラン詳細 */ private String planContents; /** * プランオプション */ private String planOption; /** * ボリュームディスカウント */ private String discount; /** * 有効アカウント */ private String activeAccount; /** * 料金 */ private String price; }
@Entity @Table(name="billing_storedata") public class BillingStore implements Serializable{ @Id @Column(name="number_id") @Getter @Setter private Long numberId; @Column(name="billing_data") @Getter @Setter private String billingData; @Column(name="billing_method") @Getter @Setter private String billingMethod; }
@Data @Entity @Table(name="contractor_information") public class Contractor implements Serializable{ @Id @Column(name="number_id") @GeneratedValue(strategy = GenerationType.IDENTITY) private String numberId; @Column(name="contract_id") private String contractId; @Column(name="company") private String company; @Column(name="store_name") private String storeName; @Column(name="furigana") private String furigana; @Column(name="route") private String route; @Column(name="account") private String account; @Column(name="price") private String price; @Column(name="pay_start") private String payStart; @Column(name="plan_id") private String planId; @Column(name="billing_id") private String billingId;
@Entity @Table(name="plan_information") public class PlanInformation implements Serializable{ @Id @Column(name="plan_id") @Getter @Setter private String planId; @Column(name="plan_contents") @Getter @Setter private String planContents; @Column(name="plan_option") @Getter @Setter private String planOption; @Column(name="discount") @Getter @Setter private String discount; @Column(name="active_account") @Getter @Setter private String activeAccount; }
@Repository public interface UserRepository extends JpaRepository<Contractor, Long> {}
@Service @Transactional(rollbackOn = Exception.class) public class UserService { /** * ユーザー情報 Repository */ @Autowired UserRepository userRepository; /** * ユーザー情報新規登録 * @param user ユーザー情報 */ public void create(UserRequest userRequest) { userRepository.save(CreateUser(userRequest)); } /** * ユーザーTBLエンティティの生成 * @param userRequest ユーザー情報リクエストデータ * @return ユーザーTBLエンティティ */ private Contractor CreateUser(UserRequest userRequest) { BillingData billingData = new BillingData(); BillingStore billingStore = new BillingStore(); Contractor contractor = new Contractor(); PlanInformation planInformation = new PlanInformation(); contractor.setContractId(userRequest.getContractId()); contractor.setCompany(userRequest.getCompany()); contractor.setStoreName(userRequest.getStoreName()); contractor.setFurigana(userRequest.getFurigana()); contractor.setRoute(userRequest.getRoute()); contractor.setAccount(userRequest.getAccount()); contractor.setPayStart(userRequest.getPayStart()); contractor.setPlanId(userRequest.getPlanId()); contractor.setBillingId(userRequest.getBillingId()); contractor.setPrice(userRequest.getPrice()); billingStore.setBillingMethod(userRequest.getBillingMethod()); billingStore.setBillingData(userRequest.getBillingData()); planInformation.setPlanContents(userRequest.getPlanContents()); planInformation.setPlanOption(userRequest.getPlanOption()); planInformation.setDiscount(userRequest.getDiscount()); planInformation.setActiveAccount(userRequest.getActiveAccount()); return contractor; } }
<body> <h1>ユーザー新規登録</h1> <form th:action="@{/user/create}" th:object="${userRequest}" method="post"> <table> <tr> <th class="cell_title">契約ID</th> <th class="cell_required">※</th> <td><input type="text" th:field="*{contractId}"></td> </tr> <tr> <th class="cell_title">会社名</th> <th class="cell_required"></th> <td><input type="text" th:field="*{company}"></td> </tr> <tr> <th class="cell_title">店舗名</th> <th class="cell_required"></th> <td><input type="text" th:field="*{storeName}"></td> </tr> <tr> <th class="cell_title">フリガナ</th> <th class="cell_required"></th> <td><input type="text" th:field="*{furigana}"></td> </tr> <tr> <th class="cell_title">導入経路</th> <th class="cell_required"></th> <td><input type="text" th:field="*{route}"></td> </tr> <tr> <th class="cell_title">アカウント発行日</th> <th class="cell_required"></th> <td><input type="text" th:field="*{account}"></td> </tr> <tr> <th class="cell_title">支払い開始日</th> <th class="cell_required"></th> <td><input type="text" th:field="*{payStart}"></td> </tr> <tr> <th class="cell_title">プランID</th> <th class="cell_required"></th> <td><input type="text" th:field="*{planId}"></td> </tr> <tr> <th class="cell_title">請求ID</th> <th class="cell_required"></th> <td><input type="text" th:field="*{billingId}"></td> </tr> <tr> <th class="cell_title">請求方法</th> <th class="cell_required"></th> <td><input type="text" th:field="*{billingMethod}"></td> </tr> <tr> <th class="cell_title">請求年月</th> <th class="cell_required"></th> <td><input type="text" th:field="*{billingData}"></td> </tr> <tr> <th class="cell_title">プラン詳細</th> <th class="cell_required"></th> <td><input type="text" th:field="*{planContents}"></td> </tr> <tr> <th class="cell_title">プランオプション</th> <th class="cell_required"></th> <td><input type="text" th:field="*{planOption}"></td> </tr> <tr> <th class="cell_title">ボリュームディスカウント</th> <th class="cell_required"></th> <td><input type="text" th:field="*{discount}"></td> </tr> <tr> <th class="cell_title">有効アカウント</th> <th class="cell_required"></th> <td><input type="text" th:field="*{activeAccount}"></td> </tr> <tr> <th class="cell_title">料金</th> <th class="cell_required"></th> <td><input type="text" th:field="*{price}"></td> </tr> </table> <div class="btn_area_center"><input type="submit" value="登録" class="btn"></div> </form> </body> </html>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Orlofsky

2020/06/04 08:51

どんなことを試したのかを載せないと丸投げと誤解され易いのでは? 差し支えない範囲で、試した内容を質問に追記した方が適切なコメントが付き易いかと。
guest

回答1

0

ベストアンサー

投稿2020/06/04 09:05

sazi

総合スコア25206

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問