Sping 学习笔记7—— SpringMVC的restful 服务
来源:互联网 发布:西安 人工智能 编辑:程序博客网 时间:2024/06/05 03:36
普通的restful服务示例
package com.test.controller.rbac;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.ResponseBody;@Controller@EnableWebMvc@RequestMapping("/rest")public class RbacAdminController { @RequestMapping(value="/test1",method=RequestMethod.POST,produces={"application/json;charset=UTF-8"}) @ResponseBody public String test1(String name,String password){ System.out.println("name="+name); return "abc"; }}
web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>Archetype Created Web Application</display-name> <servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dispatcherServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>
dispatcherServlet-servlet.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:beans="http://www.springframework.org/schema/beans"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.1.xsdhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!-- 自动扫描的包名 --> <context:component-scan base-package="com.cn.ustcit.services"></context:component-scan> <context:annotation-config /> <mvc:resources mapping="/assets/**" location="/assets/" /> <mvc:resources mapping="/js/**" location="/js/" /> <!-- 默认的注解映射的支持 --> <mvc:annotation-driven ignoreDefaultModelOnRedirect="true" > </mvc:annotation-driven> <!-- 视图解释类 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/Views/" /> <!--可为空,方便实现自已的依据扩展名来选择视图解释类的逻辑 --> <property name="suffix" value=".jsp" /> </bean> <!-- HandlerMapping --> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/> <!-- HandlerAdapter --> <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/></beans>
0 0
- Sping 学习笔记7—— SpringMVC的restful 服务
- SpringMvc-restFul学习笔记
- springmvc的restful服务理解
- SpringMVC 学习笔记(五) 基于RESTful的CRUD
- SpringMVC 学习笔记(五) 基于RESTful的CRUD
- springMVC+json构建restful风格的服务
- Sping 学习笔记9——Spring ApplicationContext
- Sping 学习笔记8——SSH框架中事务的声明与配置
- springmvc学习笔记(19)-RESTful支持
- RESTful---SpringMVC学习笔记(十三)
- springmvc学习笔记 -- day05 restful风格
- SpringMvc学习笔记(四)Restful 风格
- RESTful---SpringMVC学习笔记(十三)
- springmvc学习笔记(19)-RESTful支持
- SpringMVC实现RESTful服务
- Sping学习笔记
- Sping学习笔记
- Sping学习笔记1
- 第17章 控件模版(8)——动态换肤
- K近邻算法
- intent的用途
- STM32小问题-复用调试接口JTAG/SWD为普通GPIO
- 谁拿了最多奖学金pascal程序
- Sping 学习笔记7—— SpringMVC的restful 服务
- 51Nod - 1102 单调栈
- Javascript基础(五)之循环结构
- 【原创】梵高油画用深度卷积神经网络迭代10万次是什么效果? A neural style of convolutional neural networks
- java学习记录----面向对象(一)
- 如何创建一个居中的Frame(Swing)?
- LeetCode 71. Simplify Path
- 快速排序算法思路笔记
- 关于端口(port)的一点理解