DispatcherServlet(前端控制器):相当于MVC中的controller,dispatcherServlet是整个流程控制的中心,由他调用其他组件处理用户的请求,DispatcherServlet的存在降低了组件之间的耦合性。
HandlerMapping(处理器映射器):负责根据用户的请求找到相应的Handler(处理器),springMVC提供了不同的映射器实现了不同的映射方式,例如:配置文件方式,注解方式。
Handler(处理器):在DispatcherServlet的控制下,handler对具体的用户请求进行处理。
HandlerAdapter(处理器适配器):适配器模式,通过扩展适配器,可以对更多类型的handler进行控制。
ViewResolver(视图解析器):负责将处理结果生成视图(View),SpringMVC提供了多种视图类型,即:jstlView、freemarkerView、pdfView等。
package demo.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MainApplication {
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
三、MainApplication下的Controller
package demo.boot.controller;
import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import demo.boot.entity.User;
@Controller
@RequestMapping("test") //访问test下的方法,地址栏:http://127.0.0.1:8080/test/t1
public class TestController {
@RequestMapping("t1") //访问名
@ResponseBody
public String test1(){
return "Hello World";
}
}
四、pom.xml配置
使用时需修改:
4.0.0 org.springframework.boot spring-boot-starter-parent 1.5.2.RELEASE demos.springboot hello_boot 1.0.0-SNAPSHOT war org.springframework spring-webmvc com.jolbox bonecp-spring 0.8.0.RELEASE org.springframework.boot spring-boot-starter-web org.apache.tomcat.embed tomcat-embed-jasper provided commons-fileupload commons-fileupload 1.3.1 com.sun.jersey jersey-client 1.19 com.sun.jersey jersey-core 1.19 ${project.artifactId} org.apache.maven.plugins maven-resources-plugin UTF-8 org.apache.maven.plugins maven-compiler-plugin 1.8 1.8 UTF-8 org.springframework.boot spring-boot-maven-plugin



