SpringMvc为优秀的MVC框架,拥有强大的注解
配置web.xml拦截所有请求
SpringMvc01
index.html
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-mvc.xml
springmvc
*.do
spring-mvc.xml配置
component-scan使用注解扫描所有的包,转为bean
视图解析器,controller处理之后返回到视图解析器,通过内置配置进行解析。前缀和后缀
@Controller 扫描com.java下面所有有注解的方法实例化为bean,spring
交给视图解析器Model
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloWorldController {
@RequestMapping("/helloWorld")
public String helloWorld(Model model){
model.addAttribute("message", "StringMvc你好!");
return "helloWorld";
}
}
web,xml的welcom file的html
SpringMvc
jsp
${message }