実現したいこと
画面フォームから入力情報をDBに登録したい。
発生している問題・分からないこと
Spring解体新書第2版の第8章8.2.1insertのソースを実行し、登録フォームからそれぞれデータを入力して登録ボタンを押下した際にエラーが発生しました。
エラーメッセージ
error
1There was an unexpected error (type=Internal Server Error, status=500). 2Invalid bound statement (not found): com.example.repository.UserMapper.isertOne 3org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.repository.UserMapper.isertOne 4 at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:229)
該当のソースコード
Java
1package com.example.domain.user.model; 2 3import java.util.Date; 4 5import lombok.Data; 6 7@Data 8public class MUser { 9 private String userId; 10 private String password; 11 private String userName; 12 private Date birthday; 13 private Integer age; 14 private Integer gender; 15 private Integer departmentId; 16 private String role; 17 18} 19
Java
1package com.example.repository; 2 3import org.apache.ibatis.annotations.Mapper; 4 5import com.example.domain.user.model.MUser; 6 7@Mapper 8public interface UserMapper { 9 10 /**ユーザー登録 */ 11 public int isertOne(MUser user); 12} 13
xml
1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper3.0//EN" 3 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 4<!--Mapperとxmlのマッピング--> 5<mapper namespace="com.example.repository.UserMapper"> 6 7<!--ユーザー1件登録--> 8<insert id="insertOne"> 9 insert into m_user( 10 user_id 11 ,password 12 ,user_name 13 ,birthday 14 ,age 15 ,gender 16 ,department_id 17 ,role 18 ) 19 values( 20 #{userId} 21 ,#{password} 22 ,#{userName} 23 ,#{birthday} 24 ,#{age} 25 ,#{gender} 26 ,#{departmentId} 27 ,#{role} 28 ) 29 </insert> 30 </mapper>
Java
1package com.example.domain.user.service.impl; 2 3import org.springframework.beans.factory.annotation.Autowired; 4import org.springframework.stereotype.Service; 5 6import com.example.domain.user.model.MUser; 7import com.example.domain.user.service.UserService; 8import com.example.repository.UserMapper; 9 10@Service 11public class UserServiceImpl implements UserService { 12 13 @Autowired 14 private UserMapper mapper; 15 16 /**ユーザー登録 */ 17 @Override 18 public void signup(MUser user){ 19 user.setDepartmentId(1); 20 user.setRole("ROLE_GENERAL"); 21 mapper.isertOne(user); 22 } 23 24} 25
properties
1# DataSource 2 3spring.datasorce.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE 4 5spring.datasource.driver-class-name=org.h2.Driver 6spring.datasource.username=sa 7spring.datasource.password= 8spring.datasource.sql-script-encording=UTF-8 9spring.datasource.initialize=true 10spring.sql.init.schema-locations=classpath:schema.sql 11spring.sql.init.data-locations=classpath:data.sql 12spring.datasource.generate-unique-name=false 13 14spring.messages.basename=i18n/messages,i18n/ValidationMessages 15 16#H2DB 17spring.h2.console.enabled=true 18 19#MyBatis 20mybatis.mapper-locations=classpath*:/mapper/h2/*.xml 21 22#LogLevel 23logging.level.com.example=debug
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
application.propertiesに以下の設定を加えましたが同様のエラーとなりました。
mybatis.type-aliases-package=com.example.domain.user.model
補足
参考書ではeclipseで実施しているのですが、練習のためVSCodeで実施しています。
参考書の方では、Mybatisのバージョンは2.1.4となっていますが3.0.4に変更しました。
同様にJavaのバージョンは参考書では17となっていますが、23としています。
回答1件
あなたの回答
tips
プレビュー