SpringMVC学习记录
2021-04-02 16:26
标签:spl ext xmlns let ble span info 新建 ppi
SpringMVC学习记录
1、HelloWorld
1、新建web工程,添加jar包
2、配置web.xml配置springmvc核心控制器(DispatcherServlet):作用是加载springmvc的配置文件,核心控制器自动加载默认位置配置文件,默认位置为web-inf下,默认名称为***-servlet.xml
span>app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >Archetype Created Web Application springMVC class>org.springframework.web.servlet.DispatcherServlet class>springMVC /
springMVC-servlet.xml
3、创建一个pojo
@Controller public class Test { @RequestMapping(value = "hello",method = RequestMethod.GET)//value设置请求路径,method用于约束请求类型 public String hello() { System.out.println("111"); return "success"; } }
4、编写jsp测试代码
Hello World!
测试springmvc
5、测试post请求
@RequestMapping(value = "hello",method = RequestMethod.POST) public String hello1() { System.out.println("POST"); return "success"; }
@RequestMapping解析:
占位符与占位符里值的获取示例(@pathvariable注解):
//占位符 @RequestMapping(value = "/test/{id}/{name}") public String hello2(@PathVariable("id") Integer id, @PathVariable("name") String name) { System.out.println("id" + id + ",name:" + name); return "success"; }
SpringMVC学习记录
标签:spl ext xmlns let ble span info 新建 ppi
原文地址:https://www.cnblogs.com/zhaojianhui/p/13488284.html
上一篇:Linux下安装Java
下一篇:springboot的版本依赖