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 44 <modelVersion >4.0.0</modelVersion >
55
66 <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 >
1010 </parent >
1111
1212 <groupId >io.github.dunwu.javatech</groupId >
Original file line number Diff line number Diff line change 7575 <groupId >org.springframework</groupId >
7676 <artifactId >spring-webmvc</artifactId >
7777 </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 >
7892 <!-- spring end -->
7993 </dependencies >
8094
Original file line number Diff line number Diff line change 11package io .github .dunwu .javatech .controller ;
22
3+ import io .github .dunwu .javatech .service .HelloService ;
34import org .slf4j .Logger ;
45import org .slf4j .LoggerFactory ;
6+ import org .springframework .beans .factory .annotation .Autowired ;
57import org .springframework .stereotype .Controller ;
68import org .springframework .web .bind .annotation .RequestMapping ;
79import org .springframework .web .bind .annotation .RequestMethod ;
@@ -21,6 +23,9 @@ public class HelloController {
2123
2224 private final Logger log = LoggerFactory .getLogger (this .getClass ());
2325
26+ @ Autowired
27+ private HelloService helloService ;
28+
2429 /**
2530 * <p>
2631 * 在本例中,Spring将会将数据传给 hello.jsp
@@ -31,7 +36,7 @@ public class HelloController {
3136 public ModelAndView hello (@ RequestParam ("name" ) String name ) {
3237 ModelAndView mav = new ModelAndView ();
3338 mav .addObject ("message" , "你好," + name );
34- mav .setViewName (" hello" );
39+ mav .setViewName (helloService . hello () );
3540 return mav ;
3641 }
3742
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/
5959
6060## 🚪 传送
6161
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