1. SpringMVC的知识脉络
-
SpringMVC知识点梳理
SpringMVC知识点梳理 -
官网
网址:https://docs.spring.io/spring-framework/docs/current/reference/html/web.html -
SpringMVC的运行原理
iSpringMVC的运行原理
2. SpringMVC的简单使用
-
SpringMVC的简单使用
SpringMVC的简单使用
- SpringMVC的操作相关参考
1、spring、SpringMVC、servlet的依赖
org.springframework
spring-context
5.1.6.RELEASE
org.springframework
spring-webmvc
5.1.6.RELEASE
org.springframework
spring-web
5.1.6.RELEASE
javax.servlet
javax.servlet-api
3.1.0
provided
javax.servlet.jsp
javax.servlet.jsp-api
2.3.3
provided
2、springmvc.xml文件的约束
3、jackson的依赖(在使用@ResponseBody 的情况下需要引入以下内容)
如果用2.75以下的版本,就有可能出现兼容性问题
com.fasterxml.jackson.core
jackson-core
2.9.5
com.fasterxml.jackson.core
jackson-databind
2.9.5
3. SpringMVC+FreeMarker完成业务操作
-
SpringMVC+FreeMarker的整合
SpringMVC+FreeMarker的整合的操作步骤
- 在上方的SpringMVC项目中加入FreeMarker的依赖
org.freemarker
freemarker
2.3.23
org.springframework
spring-context-support
3.2.9.RELEASE
- 配置springmvc.xml文件中的FreeMarker相关配置
*.ftl
- 创建freemarker.properties
#设置标签类型([],<>)
tag_syntax=auto_detect
#模板缓存时间
template_update_delay=2
#默认编码
default_encoding=UTF-8
#输出编码
output_encoding=UTF-8
#本地化
locale=zh_CN
#Date格式化
date_format=yyyy-MM-dd
#Time格式化
time_format=HH:mm:ss
#Datetime格式化
datetime_format=yyyy-MM-dd HH:mm:ss
- 创建helloftl.ftl
Title
Hello, ${name}!!!
- 创建HelloFtlController
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @Author: Neco
* @Description:
* @Date: create in 2022/5/17 23:03
*/
@Controller
public class HelloFtlController {
@RequestMapping("helloftl")
public String helloFtl(Model model) {
String name = "Neco";
model.addAttribute("name", name);
return "helloftl.ftl";
}
}
- 访问并测试结果

访问并测试结果
- 对于后续的类似列表和数据库的集成,不再过多描述
如果觉得有收获就点个赞吧,更多知识,请点击关注查看我的主页信息哦~
发表回复