博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
开启Restful
阅读量:7125 次
发布时间:2019-06-28

本文共 2478 字,大约阅读时间需要 8 分钟。

hot3.png

1、web.xml添加

HiddenHttpMethodFilter
org.springframework.web.filter.HiddenHttpMethodFilter
HiddenHttpMethodFilter
/*

2、Controller类方式上添加注解

package com.how2java.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.ModelAndView; import com.how2java.pojo.Category;import com.how2java.service.CategoryService;import com.how2java.util.Page; // 告诉spring mvc这是一个控制器类@Controller@RequestMapping("")public class CategoryController {    @Autowired    CategoryService categoryService;     @RequestMapping(value="/categories",method=RequestMethod.GET)    public ModelAndView listCategory(Page page){             ModelAndView mav = new ModelAndView();        List
cs= categoryService.list(page); int total = categoryService.total(); page.caculateLast(total); // 放入转发参数 mav.addObject("cs", cs); // 放入jsp路径 mav.setViewName("listCategory"); return mav; } @RequestMapping(value="/categories",method=RequestMethod.POST) public ModelAndView addCategory(Category category){ System.out.println("category.getName():"+category.getName()); categoryService.add(category); ModelAndView mav = new ModelAndView("redirect:/categories"); return mav; } @RequestMapping(value="/categories/{id}",method=RequestMethod.DELETE) public ModelAndView deleteCategory(Category category){ categoryService.delete(category); ModelAndView mav = new ModelAndView("redirect:/categories"); return mav; } @RequestMapping(value="/categories/{id}",method=RequestMethod.GET) public ModelAndView editCategory(Category category){ Category c= categoryService.get(category.getId()); ModelAndView mav = new ModelAndView("editCategory"); mav.addObject("c", c); return mav; } @RequestMapping(value="/categories/{id}",method=RequestMethod.PUT) public ModelAndView updateCategory(Category category){ categoryService.update(category); ModelAndView mav = new ModelAndView("redirect:/categories"); return mav; } }

 

转载于:https://my.oschina.net/u/3773221/blog/2003928

你可能感兴趣的文章
衡量数据中心好坏标准的隐性指标
查看>>
数据中心新的自动化运维技术
查看>>
物联网跑太快 通用标准却跟不上
查看>>
设计师该如何学习前端?
查看>>
七牛观察|虚拟现实元年,云能做什么?
查看>>
将门CTO沈强:人工智能时代,技术创新将全面引爆商业变革
查看>>
C语言核心之数组和指针详解
查看>>
当无线通信正式成为战略能源:5G时代的蝴蝶振翅
查看>>
在Linux终端中自定义Bash配色和提示内容
查看>>
超声波追踪技术可以暴露Tor用户的真实信息
查看>>
不是供电中断 而是网络攻击让达美航空停航
查看>>
以大数据为中心整合优势资源 全国首个“新媒体小镇”落户天津静海
查看>>
《Visual C++数字图像模式识别技术详解(第2版)》一2.1 Visual C++编程方法
查看>>
《企业级ios应用开发实战》一第3章 Objective-C 语法简介
查看>>
微软推出的一个帮助iOS开发人员将应用移植到UWP的工具
查看>>
纽约制定10万度能源储存目标 配合太阳能发展政策
查看>>
《Java安全编码标准》一1.1 错位的信任
查看>>
最新消息!全球500亿条数据被 Elasticsearch 勒索者删除,中国受灾排第二
查看>>
“神童”Tom Ding:区块链是下一代云计算和互联网的基础
查看>>
新华三,定义服务器虚拟化市场新格局
查看>>