错误:

原因:接收不到restful风格请求的参数(id值),需要添加路径变量注解

@RequestMapping(value="/book/{id}",method=RequestMethod.DELETE)
public String deleteBook(@PathVariable("id")int id) {
bookSerice.deleteBook(id);
return "redirect:/book";
}

关于路径变量的知识点:

第①种情况(单个路径参数):
@RequestMapping(value = "/book/{id}", method = RequestMethod.DELETE)
public String deleteBook(@PathVariable(value = "id") int id) {
System.out.println("删除图书 id ->" + id);
return "redirect:/index.jsp";
}

/book/{id} :{id}表示路径参数占位符

@PathVariable(value = "id") int id:表示把请求路径book/{id} id所表示的值。注入到方法参数的int id中。

当@PathVariable注解中没有标记占位符名称的时候,默认使用对应的参数名做为路径参数的名称取值。

请记住:@PathVariable标记的路径变量,不能为空,必须有值

第②种情况(多个路径参数):
@RequestMapping(value = "/book/{name}/{price}/", method = RequestMethod.POST)
public String addBook(@PathVariable("name") String name,
@PathVariable("price") BigDecimal price) {
System.out.println(name);
System.out.println(price);
System.out.println("添加图书");
return "redirect:/index.jsp";
}

在一次请求中,请求路径不是只能有一个路径参数。它可以有多个。

/book/{name}/{price}/:这里就表示这个book后面可以跟两个路径参数---{name}和{price}---这两个路径参数分别注入到请求方法的 String name,和Bigdecimal price两个参数中

@PathVariable("name") String name——表示把请求路径中的name路径参数注入到请求方法的name参数中。

@PathVariable("price") BigDecimal price——表示把请求路径中的price路径参数注入到请求方法的price参数中。

最新文章

  1. sz rz SecureCRT
  2. nodejs redis 发布订阅机制封装
  3. Android应用安全开发之浅谈网页打开APP
  4. std::vector<bool>中的坑
  5. android-8~23 View.java - dispatchTouchEvent源码
  6. Velocity语言的介绍
  7. BZOJ4152The Captain[DIjkstra]
  8. logstash 配置文件实例
  9. Apple Swift编程语言入门教程
  10. 如何在redhat下安装WineQQ
  11. Number
  12. mongod的主要参数解释
  13. Prime Land
  14. Toy Storage
  15. break point
  16. java虚拟机学习-慢慢琢磨JVM(2-1)ClassLoader的工作机制
  17. 内核空间内存申请函数kmalloc kzalloc vmalloc的区别
  18. [record]WebLogic域之创建-文本界面
  19. CAP理论与分布式事务解决方案
  20. Python WebSocket长连接心跳与短连接

热门文章

  1. html5 流式布局 弹式布局 flex
  2. python面试的100题(17)
  3. ASP.NET Identity-验证与授权及管道事件
  4. LocalDate和LocalTime的用法介绍
  5. codeforces 1269E K Integers (二分+树状数组)
  6. c++踩坑大法好 宏定义 头文件
  7. vue组件引入
  8. 【转】C# Application.DoEvent()的作用
  9. 数据库之一、数据库简介及SQL概要
  10. php 扩展引入