springMVC 框架搭建
搭建步骤
实现步骤其实非常的简单:
1.新建一个web项目
2.导入相关jar包
3.编写web.xml,注册DispatcherServlet4.编写spring mvc配置文件
5.接下来就是去创建对应的控制类,controller
6.最后完善前端视图和controller之间的对应7.测试运行调试.
使用spring MVC必须配置的三大件:
处理器映射器、处理器适配器、视图解析器
通常,我们只需要手动配置视图解析器,而处理器映射器和处理器适配器只需要开启注解驱动即可,而省去了大段的xml配置
依赖
junit
junit
4.12
org.springframework
spring-webmvc
5.1.9.RELEASE
javax.servlet
servlet-api
2.5
javax.servlet.jsp
jsp-api
2.2
javax.servlet
jstl
1.2
web.xml
<?xml version="1.0" encoding="UTF-8"?>
Springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springMVC-servelt.xml
1
Springmvc
/
psringMVC-servelt.xml
<?xml version="1.0" encoding="UTF-8"?>
controller
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping("/h1")
public String hello(Model model){
model.addAttribute("msg","hello,MVC");
return "hello";
}
}
hello.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title
${msg}
项目结构