Spring mvc demo

xiaoxiao2025-04-22  14

1.官网操作:

https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc-config

 

2.2使用IDEA,利用SpringMVC框架建立HelloWorld项目

2.2.1  view 代碼:

<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>$Title$</title> </head> <body> 你好 </body> </html>

 

2.2.3 控制器代碼:

public class HiController { /* @RequestMapping("/say") public String say() { return "/WEB-INF/jsp/say.jsp"; } */ @RequestMapping("/say") public String say() { ModelAndView modelAndView = new ModelAndView(); modelAndView.setViewName("test"); return "index"; } }

 

 

2.2.3   顯示結果:

2.2.4 運行結果:

 

 

參考資料:

https://www.cnblogs.com/sunniest/p/4555801.html

https://www.cnblogs.com/chenlinghong/p/8339555.html

 

相關代碼:

代碼:下載代碼

 

 

转载请注明原文地址: https://www.6miu.com/read-5028848.html

最新回复(0)