File tree Expand file tree Collapse file tree 6 files changed +126
-0
lines changed
main/java/com/hand/springbootdataaccess
test/java/com/hand/springbootdataaccess Expand file tree Collapse file tree 6 files changed +126
-0
lines changed Original file line number Diff line number Diff line change 41
41
<artifactId >druid-spring-boot-starter</artifactId >
42
42
<version >1.1.0</version >
43
43
</dependency >
44
+ <dependency >
45
+ <groupId >org.mybatis.spring.boot</groupId >
46
+ <artifactId >mybatis-spring-boot-starter</artifactId >
47
+ <version >1.3.2</version >
48
+ </dependency >
44
49
</dependencies >
45
50
46
51
<build >
Original file line number Diff line number Diff line change 1
1
package com .hand .springbootdataaccess ;
2
2
3
+ import org .mybatis .spring .annotation .MapperScan ;
3
4
import org .springframework .boot .SpringApplication ;
4
5
import org .springframework .boot .autoconfigure .SpringBootApplication ;
5
6
6
7
@ SpringBootApplication
8
+ @ MapperScan (value = "com.hand.springbootdataaccess.mapper" )
7
9
public class SpringbootDataaccessApplication {
8
10
9
11
public static void main (String [] args ) {
Original file line number Diff line number Diff line change
1
+ package com .hand .springbootdataaccess .mapper ;
2
+
3
+ import java .util .List ;
4
+
5
+ import com .hand .springbootdataaccess .pojo .Report ;
6
+ import org .apache .ibatis .annotations .Select ;
7
+
8
+ /**
9
+ * @author zijian.zeng@hand-china.com
10
+ * @since 2023-01-29
11
+ */
12
+ public interface ReportMapper {
13
+
14
+ @ Select ("select * from report;" )
15
+ List <Report > findAllReport ();
16
+ }
Original file line number Diff line number Diff line change
1
+ package com .hand .springbootdataaccess .pojo ;
2
+
3
+ /**
4
+ * @author zijian.zeng@hand-china.com
5
+ * @since 2023-01-29
6
+ */
7
+ public class Report {
8
+
9
+ private Long id ;
10
+
11
+ private String content ;
12
+
13
+ private int type ;
14
+
15
+ private int status ;
16
+
17
+ public int getStatus () {
18
+ return status ;
19
+ }
20
+
21
+ public void setStatus (int status ) {
22
+ this .status = status ;
23
+ }
24
+
25
+ public Long getId () {
26
+ return id ;
27
+ }
28
+
29
+ public void setId (Long id ) {
30
+ this .id = id ;
31
+ }
32
+
33
+ public String getContent () {
34
+ return content ;
35
+ }
36
+
37
+ public void setContent (String content ) {
38
+ this .content = content ;
39
+ }
40
+
41
+ public int getType () {
42
+ return type ;
43
+ }
44
+
45
+ public void setType (int type ) {
46
+ this .type = type ;
47
+ }
48
+
49
+ @ Override
50
+ public String toString () {
51
+ return "Report{" +
52
+ "id=" + id +
53
+ ", content='" + content + '\'' +
54
+ ", type=" + type +
55
+ ", status=" + status +
56
+ '}' ;
57
+ }
58
+ }
Original file line number Diff line number Diff line change
1
+ package com .hand .springbootdataaccess .service ;
2
+
3
+ import java .util .List ;
4
+
5
+ import com .hand .springbootdataaccess .mapper .ReportMapper ;
6
+ import com .hand .springbootdataaccess .pojo .Report ;
7
+ import org .apache .commons .logging .Log ;
8
+ import org .apache .commons .logging .LogFactory ;
9
+ import org .springframework .beans .factory .annotation .Autowired ;
10
+ import org .springframework .stereotype .Service ;
11
+
12
+ /**
13
+ * @author zijian.zeng@hand-china.com
14
+ * @since 2023-01-29
15
+ */
16
+ @ Service
17
+ public class ReportService {
18
+
19
+ Log log = LogFactory .getLog (ReportService .class );
20
+
21
+
22
+ @ Autowired
23
+ private ReportMapper reportMapper ;
24
+
25
+
26
+ public List <Report > findAllReport () {
27
+
28
+ List <Report > allReport = reportMapper .findAllReport ();
29
+ log .info ("查询到的信息: " + allReport );
30
+ return allReport ;
31
+ }
32
+
33
+
34
+ }
Original file line number Diff line number Diff line change 4
4
import java .sql .ResultSet ;
5
5
import java .sql .SQLException ;
6
6
import java .sql .Statement ;
7
+ import java .util .List ;
7
8
import javax .sql .DataSource ;
8
9
10
+ import com .hand .springbootdataaccess .pojo .Report ;
9
11
import com .hand .springbootdataaccess .pojo .SimpleBean ;
12
+ import com .hand .springbootdataaccess .service .ReportService ;
10
13
import org .junit .jupiter .api .Test ;
11
14
import org .junit .runner .RunWith ;
12
15
import org .springframework .beans .factory .annotation .Autowired ;
@@ -23,6 +26,9 @@ class SpringbootDataaccessApplicationTests {
23
26
@ Autowired
24
27
private SimpleBean simpleBean ;
25
28
29
+ @ Autowired
30
+ private ReportService reportService ;
31
+
26
32
@ Test
27
33
void contextLoads () throws SQLException {
28
34
Connection connection = dataSource .getConnection ();
@@ -35,4 +41,9 @@ void contextLoads() throws SQLException {
35
41
36
42
}
37
43
44
+ @ Test
45
+ void findReport () {
46
+ reportService .findAllReport ();
47
+ }
48
+
38
49
}
You can’t perform that action at this time.
0 commit comments