关于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 ...
随机推荐
- 数据结构——栈的实现(数组、Java)
巩固数据结构 栈是一种有限制的线性表 只能对表尾进行操作 package com.shine.test.datastruct; import java.util.Arrays; public clas ...
- 记一个男默女泪的 BUG
姗姗来迟的词频统计代码 BUG 的发现 1. 此前提交的第一次代码作业总结博客 http://www.cnblogs.com/ustczwq/p/8680704.html 2. BUG 本天成,妙手偶 ...
- PIC EEPROM问题
1.通过export出来的Hex烧录,EEPROM内容会根据Hex中关于EEPROM的定义而改变. 2.通过编译源文件烧录,如果没有勾选Preserve EEPROM on program则EEPRO ...
- 2017/01/07 学习笔记 jar包,maven
① 关于tar,jar,war文件 tar是通用的另一种打包格式,为了部署到服务器时方便. jar是java app server识别的java部署格式,其实是Zip文件,只是内部的文件有规范. wa ...
- 创建一个dynamics CRM workflow (一) - Introduction to Custom Workflows
Workflow: Use this process to model and automate real world business processes. These processes can ...
- java中的标识符
程序员自己定义的名称,例如类名,方法名,变量等等 标识符命名的规则 1.只能由字母(a-z,A-Z),数字(0-9),下划线(_)和美元符号($)组成 2.不能以数字开头 3.不能与关键字重名 4.严 ...
- CentOS7 使用 firewalld 打开关闭 防火墙 与 端口!!
1.firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status f ...
- JS中的map
定义和用法: map() 方法返回一个新数组,数组中的元素为原始数组元素调用函数处理后的值. map() 方法按照原始数组元素顺序依次处理元素. 注意: map() 不会对空数组进行检测. 注意: m ...
- 10分钟 PySimpleGUI 图形界面入门
import PySimpleGUI as sg layout = [ [sg.Text('Enter a Number')], [sg.Input()], [sg.OK()] ] event,(nu ...
- Codeforces 789A Anastasia and pebbles( 水 )
链接:传送门 题意:这个人每次都去公园捡石子,她有两个口袋,每个口袋最多装 k 个石子,公园有 n 种石子,每种石子 w[i] 个,询问最少几天能将石子全部捡完 思路:排个序,尽量每天都多装,如果 k ...