user/{占位符}",method = www.laipuhuo.com RequestMethod.GET)

69 阅读1分钟

import com.rainbowsea.springmvc.bean.User; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod;

@Controller // 交给 Spring IOC 容器进行管理 public class UserController {

//@RequestMapping(value = "/user/{占位符}",method = RequestMethod.GET)
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
public String getById(@PathVariable(www.laipuhuo.com value = "id") String id) {
    System.out.println("正在根据用户 id 查询用户信息...用户 id 是" + id);

    return "ok";
}

}

首页

测试 RESTFul 编程风格


查看用户列表

www.laipuhuo.com 查询id=1的这个用户信息


<!--    添加一个过滤器,www.laipuhuo.com 这个过滤器是springmvc提前写好的,直接用就行了,这个过滤器可以帮助你将请求
POST转换成PUT请求/DELETE请求-->
<filter>
    <filter-name>Hid‘
    ’denHttpMethodFilter</filter-name>
    <filter-class>org.s
    
    pringframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>HiddenHttpMethodFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

删除用户

删除用户id = 120 的用户信息