File tree Expand file tree Collapse file tree 6 files changed +67
-5
lines changed
javatech-mq/javatech-kafka-springboot
main/java/io/github/dunwu/javatech
test/java/io/github/dunwu/javatech Expand file tree Collapse file tree 6 files changed +67
-5
lines changed Original file line number Diff line number Diff line change 4
4
<modelVersion >4.0.0</modelVersion >
5
5
6
6
<parent >
7
- <groupId >io.github.dunwu</groupId >
8
- <artifactId >dunwu-starter-parent </artifactId >
9
- <version >0.5.6 </version >
7
+ <groupId >io.github.dunwu.boot </groupId >
8
+ <artifactId >dunwu-boot </artifactId >
9
+ <version >1.0.8 </version >
10
10
</parent >
11
11
12
12
<groupId >io.github.dunwu.javatech</groupId >
Original file line number Diff line number Diff line change 75
75
<groupId >org.springframework</groupId >
76
76
<artifactId >spring-webmvc</artifactId >
77
77
</dependency >
78
+ <dependency >
79
+ <groupId >org.springframework</groupId >
80
+ <artifactId >spring-test</artifactId >
81
+ </dependency >
82
+ <dependency >
83
+ <groupId >junit</groupId >
84
+ <artifactId >junit</artifactId >
85
+ <scope >test</scope >
86
+ </dependency >
87
+ <dependency >
88
+ <groupId >org.assertj</groupId >
89
+ <artifactId >assertj-core</artifactId >
90
+ <scope >test</scope >
91
+ </dependency >
78
92
<!-- spring end -->
79
93
</dependencies >
80
94
Original file line number Diff line number Diff line change 1
1
package io .github .dunwu .javatech .controller ;
2
2
3
+ import io .github .dunwu .javatech .service .HelloService ;
3
4
import org .slf4j .Logger ;
4
5
import org .slf4j .LoggerFactory ;
6
+ import org .springframework .beans .factory .annotation .Autowired ;
5
7
import org .springframework .stereotype .Controller ;
6
8
import org .springframework .web .bind .annotation .RequestMapping ;
7
9
import org .springframework .web .bind .annotation .RequestMethod ;
@@ -21,6 +23,9 @@ public class HelloController {
21
23
22
24
private final Logger log = LoggerFactory .getLogger (this .getClass ());
23
25
26
+ @ Autowired
27
+ private HelloService helloService ;
28
+
24
29
/**
25
30
* <p>
26
31
* 在本例中,Spring将会将数据传给 hello.jsp
@@ -31,7 +36,7 @@ public class HelloController {
31
36
public ModelAndView hello (@ RequestParam ("name" ) String name ) {
32
37
ModelAndView mav = new ModelAndView ();
33
38
mav .addObject ("message" , "你好," + name );
34
- mav .setViewName (" hello" );
39
+ mav .setViewName (helloService . hello () );
35
40
return mav ;
36
41
}
37
42
Original file line number Diff line number Diff line change
1
+ package io .github .dunwu .javatech .service ;
2
+
3
+ import org .springframework .stereotype .Service ;
4
+
5
+ /**
6
+ * @author 11123558
7
+ * @date 2022-07-28
8
+ */
9
+ @ Service
10
+ public class HelloService {
11
+
12
+ public String hello () {
13
+ return "hello" ;
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ package io .github .dunwu .javatech ;
2
+
3
+ import io .github .dunwu .javatech .service .HelloService ;
4
+ import org .assertj .core .api .Assertions ;
5
+ import org .junit .Test ;
6
+ import org .junit .runner .RunWith ;
7
+ import org .springframework .beans .factory .annotation .Autowired ;
8
+ import org .springframework .test .context .ContextConfiguration ;
9
+ import org .springframework .test .context .junit4 .SpringJUnit4ClassRunner ;
10
+
11
+ /**
12
+ * 单元测试
13
+ * @author 11123558
14
+ * @date 2022-07-28
15
+ */
16
+ @ RunWith (SpringJUnit4ClassRunner .class )
17
+ @ ContextConfiguration (locations = {"classpath:spring/spring-servlet.xml" })
18
+ public class HelloControllerTests {
19
+
20
+ @ Autowired
21
+ private HelloService service ;
22
+
23
+ @ Test
24
+ public void test () {
25
+ String msg = service .hello ();
26
+ Assertions .assertThat ("hello" ).isEqualTo (msg );
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -59,4 +59,4 @@ permalink: /pages/ca58e7/
59
59
60
60
## 🚪 传送
61
61
62
- ◾ 🏠 [ JAVA-TUTORIAL 首页 ] ( https://github.com/dunwu/java-tutorial ) ◾ 🎯 [ 我的博客 ] ( https://github.com/dunwu/ blog ) ◾
62
+ ◾ 💧 [ 钝悟的 IT 知识图谱 ] ( https://dunwu. github.io/waterdrop/ ) ◾ 🎯 [ 钝悟的博客 ] ( https://dunwu. github.io/ blog/ ) ◾
You can’t perform that action at this time.
0 commit comments