質問編集履歴
2
コードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -43,20 +43,115 @@
|
|
43
43
|
|
44
44
|
### 該当のソースコード
|
45
45
|
|
46
|
+
画像も張っていますがこちらにコードも載せておきます。
|
47
|
+
サービスクラスで、BookMapperが見つからずにエラーが起きているようです。
|
48
|
+
|
46
49
|
```BookService.java
|
47
50
|
@Service
|
48
51
|
public class BookService {
|
49
52
|
@Autowired
|
50
|
-
public BookMapper
|
53
|
+
public BookMapper bookMapper;
|
51
54
|
|
52
55
|
public void delete(Long bookId){
|
53
|
-
|
56
|
+
bookMapper.delete(bookId);
|
54
|
-
}
|
57
|
+
}
|
55
|
-
|
56
58
|
}
|
57
59
|
|
60
|
+
```
|
61
|
+
|
62
|
+
```BookMapper.xml
|
63
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
64
|
+
<!DOCTYPE mapper
|
65
|
+
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
66
|
+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
67
|
+
|
68
|
+
<mapper namespace="com.example.demo.repository.BookMapper">
|
69
|
+
|
70
|
+
<delete id="delete">
|
71
|
+
delete from book
|
72
|
+
where id = #{bookId};
|
73
|
+
</delete>
|
74
|
+
</mapper>
|
75
|
+
```
|
76
|
+
|
77
|
+
```BookMapper.java
|
78
|
+
package com.example.demo.repository;
|
79
|
+
|
80
|
+
import org.apache.ibatis.annotations.Mapper;
|
81
|
+
|
82
|
+
@Mapper
|
83
|
+
public interface BookMapper{
|
84
|
+
|
85
|
+
void delete(Long bookId);
|
86
|
+
|
87
|
+
}
|
88
|
+
```
|
89
|
+
|
90
|
+
```application.properties
|
91
|
+
spring.application.name=Book
|
92
|
+
|
93
|
+
# MyBatis設定
|
94
|
+
mybatis.config-location=classpath:mybatis-config.xml
|
95
|
+
|
96
|
+
## 以下h2データベース
|
97
|
+
spring.h2.console.enabled=true
|
98
|
+
spring.datasource.url=jdbc:h2:mem:px_test;MODE=MYSQL
|
99
|
+
spring.datasource.username=sa
|
58
|
-
|
100
|
+
spring.datasource.password=
|
101
|
+
spring.datasource.driverClassName=org.h2.Driver
|
102
|
+
spring.datasource.initialization-mode=always
|
103
|
+
#spring.datasource.schema=classpath:database/schema.sql
|
104
|
+
#spring.datasource.data=classpath:database/data.sql
|
105
|
+
spring.sql.init.schema-locations=classpath:database/schema.sql
|
106
|
+
spring.sql.init.data-locations=classpath:database/data.sql
|
107
|
+
spring.datasource.platform=h2
|
59
|
-
|
108
|
+
spring.h2.console.path=/h2-console
|
109
|
+
```
|
110
|
+
|
111
|
+
```build.gradle
|
112
|
+
plugins {
|
113
|
+
id 'java'
|
114
|
+
id 'org.springframework.boot' version '3.3.0'
|
115
|
+
id 'io.spring.dependency-management' version '1.1.5'
|
116
|
+
}
|
117
|
+
|
118
|
+
group = 'com.example'
|
119
|
+
version = '0.0.1-SNAPSHOT'
|
120
|
+
|
121
|
+
java {
|
122
|
+
sourceCompatibility = '21'
|
123
|
+
}
|
124
|
+
|
125
|
+
configurations {
|
126
|
+
compileOnly {
|
127
|
+
extendsFrom annotationProcessor
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
repositories {
|
132
|
+
mavenCentral()
|
133
|
+
}
|
134
|
+
|
135
|
+
dependencies {
|
136
|
+
|
137
|
+
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
|
138
|
+
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
139
|
+
implementation 'org.springframework.boot:spring-boot-starter-validation'
|
140
|
+
implementation 'org.springframework.boot:spring-boot-starter-web'
|
141
|
+
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
142
|
+
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.0'
|
143
|
+
compileOnly 'org.projectlombok:lombok'
|
144
|
+
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
145
|
+
runtimeOnly 'com.h2database:h2'
|
146
|
+
runtimeOnly 'com.mysql:mysql-connector-j'
|
147
|
+
annotationProcessor 'org.projectlombok:lombok'
|
148
|
+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
149
|
+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
|
150
|
+
}
|
151
|
+
|
152
|
+
tasks.named('test') {
|
153
|
+
useJUnitPlatform()
|
154
|
+
}
|
60
155
|
```
|
61
156
|
|
62
157
|
### 試したこと・調べたこと
|
1
誤字の訂正をしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
エラーを解決する方法を教えてください。エラーの詳細は下記に記載しています。
|
4
4
|
|
5
5
|
・BookService.java
|
6
|
-
![BookService.java](https://ddjkaamml8q8x.cloudfront.net/questions/2024-06-13/38
|
6
|
+
![BookService.java](https://ddjkaamml8q8x.cloudfront.net/questions/2024-06-13/f38676a7-d548-4675-a45e-66a077894580.png)
|
7
7
|
・BookMapper.java
|
8
8
|
![BookMapper.java](https://ddjkaamml8q8x.cloudfront.net/questions/2024-06-13/8dd305e1-a440-40b7-bb85-0a32700b87ff.png)
|
9
9
|
・BookMapper.xml
|