您当前的位置: 首页 >  spring

wespten

暂无认证

  • 0浏览

    0关注

    899博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

SpringMvc框架搭建

wespten 发布时间:2018-08-21 02:15:56 ,浏览量:0

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 }

 

 

 

 

 

 

 

 

 

 

关注
打赏
1665965058
查看更多评论
立即登录/注册

微信扫码登录

0.0471s