关于spring和extjs对接的过程简述
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param> <listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener> <listener>
<listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
</listener> <servlet>
<servlet-name>RestEasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RestEasy</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping> <!-- 编码 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <context:component-scan base-package="lmx.phone" />
</beans>
package lmx.phone.service; import javax.ws.rs.GET;
import javax.ws.rs.Path; import lmx.phone.util.ExtJSResponse; import org.springframework.stereotype.Service; @Service
@Path("esper")
public class EsperService { @Path("phone")
@GET
public ExtJSResponse phoneService() {
System.out.println("rest works");
return null;
} }
package lmx.phone.util; import java.util.HashMap; /**
* used to integrates with ExtJS 4.x data stores.<br>
* In ExtJS, the data store use following format to verify the result:
* <p/>
* <pre>
* "{"success":false,"data":"","message":"VERBOSE ERROR"}"
* </pre>
*
* @author MiXian
*/
public class ExtJSResponse extends HashMap<String, Object> {
/**
*
*/
private static final long serialVersionUID = -2791356338016228077L; public static ExtJSResponse successRes() {
return new ExtJSResponse(true);
} public static ExtJSResponse successRes4Find(Object data,Integer total) {
ExtJSResponse res = new ExtJSResponse(true);
res.setData(data);
res.put("total",total);
return res;
} public static ExtJSResponse successResWithData(Object data) {
ExtJSResponse res = new ExtJSResponse(true);
res.setData(data);
return res;
} public static ExtJSResponse errorRes(String error) {
ExtJSResponse res = new ExtJSResponse(false);
res.setErrorMsg(error);
return res;
} public ExtJSResponse() {
} public ExtJSResponse(boolean success) {
super();
setSuccess(success);
} public boolean isSuccess() {
return (Boolean) get("success");
} public void setSuccess(boolean success) {
put("success", success);
} public void setErrorMsg(String errorMsg) {
put("error", errorMsg);
} public String getErrorMsg() {
return (String) get("error");
} public void setData(Object data) {
put("data", data);
} public Object getData() {
return get("data");
} }
关于前台和后台之间的交互:
1、extjs发送ajax请求,以“/rest/*”的形式。
2、web.xml捕捉到请求之后,将请求发给DispatherServlet
3、DispatherServlet将请求发给配置的package
4、package扫描所有的“@service”类,寻找匹配的方法来处理请求,并返回给前端一个json数据串。json数据串通过ExtjsResonse来生成一个基本的内容。
5、前端根据json数据串来改变前端的内容
关于spring和extjs对接的过程简述的更多相关文章
- 工厂模式模拟Spring的bean加载过程
一.前言 在日常的开发过程,经常使用或碰到的设计模式有代理.工厂.单例.反射模式等等.下面就对工厂模式模拟spring的bean加载过程进行解析,如果对工厂模式不熟悉的,具体可以先去学习一下工厂 ...
- Spring之IOC容器初始化过程
Ioc容器的初始化是由refresh()方法来启动的,这个方法标志着Ioc容器的正式启动. 具体来说这个启动过程包括三个基本过程: 1.BeanDifinition的Resource定位 2.Bean ...
- 升级到 ExtJS 5的过程记录
升级到 ExtJS 5的过程记录 最近为公司的一个项目创建了一个 ExtJS 5 的分支,顺便记录一下升级到 ExtJS 5 所遇到的问题以及填掉的坑.由于 Sencha Cmd 的 sencha ...
- spring internalTransactionAdvisor 事务 advisor 初始化过程
spring internalTransactionAdvisor 事务 advisor 初始化过程:
- Spring容器的创建刷新过程
Spring容器的创建刷新过程 以AnnotionConfigApplicationContext为例,在new一个AnnotionConfigApplicationContext的时候,其构造函数内 ...
- Spring IOC容器创建bean过程浅析
1. 背景 Spring框架本身非常庞大,源码阅读可以从Spring IOC容器的实现开始一点点了解.然而即便是IOC容器,代码仍然是非常多,短时间内全部精读完并不现实 本文分析比较浅,而完整的IOC ...
- Spring Security 解析(二) —— 认证过程
Spring Security 解析(二) -- 认证过程 在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security .S ...
- Spring Security 解析(一) —— 授权过程
Spring Security 解析(一) -- 授权过程 在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security .S ...
- Spring Bean 的加载过程
Spring Bean 的加载过程 一个是populateBean,一个是initializeBean,这两个方法完成了bean的赋值与初始化. 这里有一个BeanDefinitionValueRes ...
随机推荐
- 使用Custom scrollbar(彩色滚动条)插件实现WordPress滚动条变色的方法
1.在插件中心关键词搜索Custom scrollbar 2.按照说明操作就行 查看演示:sheji.xinlvtian.com
- Redis入门笔记-redis内部数据结构(01)
redis是一个轻量级的Nodsql数据库,使用kev-value的形式存储数据,在redis的世界里,没有整数.浮点数等概念,大多数情况下数据以字符串形式展现,偶尔会出现Long类型数据的场景. 一 ...
- Walking on the path of Redis --- Introduction and Installation
废话开篇 以前从来没听说过有Redis这么个玩意,无意间看到一位仁兄的博客,才对其有所了解,所以决定对其深入了解下.有不对的地方还请各位指正. Redis介绍 下面是官方的介绍,不喜欢english的 ...
- python安装Django需要环境
Django==1.10.3 -e git+https://github.com/duoshuo/duoshuo-python-sdk.git#egg=duoshuo-python-sdk djang ...
- 组装自己的tesla超级计算机
原文链接:blog.csdn.net/xqj198404/article/details/20016279 NVIDIA链接:http://www.nvidia.cn/object/tesla_bui ...
- C#——面对对象之封装、继承、多态的简单理解
一.封装 隐藏对象的属性和实现细节,仅对外公开接口,控制在程序中属性的读取和修改的访问级别. 简单来多,就是讲我们所需要的代码打包封装进入一个类里面,便于我们调用,操作.这就是封装. 这样就隔离了具体 ...
- python编写简单的html登陆页面(1)
1 html 打开调式效果如下 2 用python后台编写 # coding:utf-8# 从同一个位置导入多个工具,# 这些工具之间可以用逗号隔开,同时导入# render_template渲染 ...
- 洛谷P3807 【模板】卢卡斯定理_组合数学模板
Code: #include<cstdio> using namespace std; typedef long long LL; const int maxn=1000000+2; LL ...
- Python笔记5----集合set
1.集合的概念:无序不重复 分为可变集合(set())和不可变集合(frozenset)两种 2.创建集合 aset=set('hello') >>aset={'h','e','l','o ...
- [luogu4107 HEOI2015] 兔子与樱花(树形dp+贪心)
传送门 Description 很久很久之前,森林里住着一群兔子.有一天,兔子们突然决定要去看樱花.兔子们所在森林里的樱花树很特殊.樱花树由n个树枝分叉点组成,编号从0到n-1,这n个分叉点由n-1个 ...