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

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

新規登録して質問してみよう
ただいま回答率
85.50%
データベース

データベースとは、データの集合体を指します。また、そのデータの集合体の共用を可能にするシステムの意味を含めます

MyBatis

MyBatisはJavaや.NET Frameworkでなどで使用できる、SQL文や、ストアドプロシージャをオブジェクトと紐付けるO/Rマッピングフレームワークです。

Thymeleaf

Thymeleaf(タイムリーフ)とは、Java用のテンプレートエンジンで、特定のフレームワークに依存せず使用することが可能です。

Spring Boot

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

Q&A

0回答

1874閲覧

vscode+Spring boot+thymeleaf+MyBatis//データを取得しドロップダウンメニューを表示する

Karin-0401

総合スコア1

データベース

データベースとは、データの集合体を指します。また、そのデータの集合体の共用を可能にするシステムの意味を含めます

MyBatis

MyBatisはJavaや.NET Frameworkでなどで使用できる、SQL文や、ストアドプロシージャをオブジェクトと紐付けるO/Rマッピングフレームワークです。

Thymeleaf

Thymeleaf(タイムリーフ)とは、Java用のテンプレートエンジンで、特定のフレームワークに依存せず使用することが可能です。

Spring Boot

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

0グッド

0クリップ

投稿2021/08/13 16:01

前提・実現したいこと

vscode+Spring boot+thymeleaf+HTML+CSS+MyBatisを使いドロップダウンメニューを表示する

~過程~
①MyBatisなどでデータベースに登録している項目を取得してくる
②thymeleafを使ってeach文を回す
③取得してきたデータを元に項目を表示しドロップダウンメニューを作る

発生している問題・エラーメッセージ

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-08-13 19:05:25.171 ERROR 5520 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'shopMstService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'shopMstService': Unsatisfied dependency expressed through field 'shopMstMapper'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shopMstMapper' defined in file [C:\Users\m-matsui\Desktop\pl_practice\user_manage2\user_manage\target\classes\com\server\free\user_manage\mapper\shopMst\ShopMstMapper.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/server/free/user_manage/mapper/shopMst/ShopMstMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Wrong namespace. Expected 'com.server.free.user_manage.mapper.shopMst.ShopMstMapper' but found 'com.server.free.user_manage.mapper.shopMst.ShopMst.ShopMstMapper'. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:643) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:130) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.2.9.RELEASE.jar:5.2.9.RELEASE] ...

該当のソースコード

【UserController.java】 package com.server.free.user_manage.controllers.setting; import java.util.List; import com.server.free.user_manage.entities.User; import com.server.free.user_manage.services.ShopMstService; import com.server.free.user_manage.services.UserMstService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class UserController { @Autowired ShopMstService shopMstService; // 画面の表示 @RequestMapping("/UserSearch") public String searchScreen(Model model){ System.out.println("画面が表示されます"); // 追記s List<String> storeName = shopMstService.storeNameDisplay(); model.addAttribute("storeNamelist", storeName); return "mian/setting/UserSearch"; } //http://localhost:8080/tgcars-works/UserSearch } //-------------------------------------------------------------------------------------------- 【ShopMstService.java】 package com.server.free.user_manage.services; import java.util.List; import com.server.free.user_manage.mapper.shopMst.ShopMstMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service public class ShopMstService { @Autowired private ShopMstMapper shopMstMapper; public List<String> storeNameDisplay(){ return shopMstMapper.storeNameDisplay(); } } 【ShopMstMapper.java】 package com.server.free.user_manage.mapper.shopMst; import java.util.List; import org.apache.ibatis.annotations.Mapper; @Mapper public interface ShopMstMapper { public List<String> storeNameDisplay(); } 【ShopMstMapper.xml】 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!-- 決まり文句/////////////////////////////////////////////////////////////////////////////////////////// --> <mapper namespace="com.server.free.user_manage.mapper.shopMst.ShopMst.ShopMstMapper"> <select id="storeNameDisplay" resultType="String" > <!-- SELECT【検索】 --> SELECT SHOP_CD shopCD; SHOP_NM shopNM; REC_REG_USER_ID recRegUserId; REC_REG_YMD recRegYmd; REC_REG_JKK recRegJkk; REC_UPD_USER_ID recUpdUserId; REC_UPD_YMD recUpdUserYmd; REC_UPD_JKK recUpdUserJkk; FROM user_mst </select> </mapper> 【Shop.java】 package com.server.free.user_manage.entities; import lombok.Data; // Shopエンティティ @Data public class Shop{ private String shopCD; //店舗コード private String shopNM; //店舗名称 private String recRegUserId; //レコード登録ユーザーID private String recRegYmd; //レコード登録年月日 private String recRegJkk; //レコード登録時刻 private String recUpdUserId; //レコード更新ユーザーID private String recUpdUserYmd; //レコード更新年月日 private String recUpdUserJkk; //レコード更新時刻 } 【UserSearch.html】 <!DOCTYPE html> <html lang="ja" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <!--↑th:replace…フラグメントを参照するための属性 --> <head th:fragmeent> <title>利用者検索・一覧画面</title> <meta charset="UTF-8"> <!-- ◆本番用・・・タイムリーフを使ってCSSを反映 --> <link th:href="@{/css/main.css}" rel="stylesheet"> <link th:href="@{/css/userSearch.css}" rel="stylesheet"> </head> <body> <div th:if="${userinfo}"> <table th:object ="${userinfo}" border ="1" style="border-collapse: collapse" width="800" height="70"> <tr> <th>利用者ID</th> <th>利用者名</th> <th>店舗</th> <th>権限</th> <th>退職</th> <th>削除</th> <th>生年月日</th> <th></th> </tr> <tr th:each="userInfo:${userinfo}"> <td th:text="${userInfo.userId}"></td> <td th:text="${userInfo.userName}"></td> <td th:text="${userInfo.shopCd}"></td> <td th:text="${userInfo.authorityLv}"></td> <td th:text="${userInfo.tisykFlg}"></td> <td th:text="${userInfo.deleteFlg}"></td> <td th:text="${userInfo.birthDay}"></td> <td> <!-- <form method ="post" action="/tgcars-works/userChang/pushButton"></form> </form> --> <input type="submit" class ="changeButton" name ="chang" value ="変更"> </td> </tr> </table> </body> </html>

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

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

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

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

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

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問