续写一个二叉树的完整实现――前序・中序・后序・测试
2012-11-17 11:00
399 查看
随便写着玩玩.不要太认真哦^^
关于一大堆的理论就不讲了,什么MVC之类的,老人不削一看,新人又看不懂
总结一下其实是我也不清楚.^^哈哈.
再我看来,添加spring进来就是为了简化RPC的服务端代码,然后在其中注入dao比较方便..没其他的了~
1.首先把spring2.5中的spring.jar,spring-webmvc.jar,aspectjrt.jar等等jar包添加到项目中.
2.创建一个包,然后添加一个Controller类进来.这个类要代替RPC服务的继承父类,所以我们把这个Controller继承RemoteServiceServlet,这样,以后RPC的服务就可以直接继承这个Controller了
然后让这个Controller实现几个口:Controller,ServletConfigAware,ServletContextAware.这里就不说为什么要继承这几个接口了.下面就是这个类的所有代码.
3.改造GreetingService让它处于spring的监管下
打开GreetingService,然后去掉 @RemoteServiceRelativePath("greet") 注解.
打开GreetingServiceImpl,修改父类为我们刚刚写的Controller
然后给它添加一个注解 @Service("greetingService"),这个service是org.springframework.stereotype此包下的.
4.修改web.xml
5.修改GoogleMapV3.gwt.xml,添加servlet
6.给项目添加一个spring配置文件.具体做法是在项目中添加一个源包resources,然后在里面添加一个包spring,然后添加applicationContext.xml到其中
7.为GXT注册新的servlet地址,添加以下代码到你自己的代码中就可以了
好了...重新启动下,看看效果是不是一样的呢?^^
过会再发个gxt配合Hibernate使用的方案.
http://www.nptpark.com
关于一大堆的理论就不讲了,什么MVC之类的,老人不削一看,新人又看不懂
总结一下其实是我也不清楚.^^哈哈.
再我看来,添加spring进来就是为了简化RPC的服务端代码,然后在其中注入dao比较方便..没其他的了~
1.首先把spring2.5中的spring.jar,spring-webmvc.jar,aspectjrt.jar等等jar包添加到项目中.
2.创建一个包,然后添加一个Controller类进来.这个类要代替RPC服务的继承父类,所以我们把这个Controller继承RemoteServiceServlet,这样,以后RPC的服务就可以直接继承这个Controller了
然后让这个Controller实现几个口:Controller,ServletConfigAware,ServletContextAware.这里就不说为什么要继承这几个接口了.下面就是这个类的所有代码.
package com.yx.map.spring; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.context.ServletConfigAware; import org.springframework.web.context.ServletContextAware; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.Controller; import com.google.gwt.user.server.rpc.RemoteServiceServlet; /** * * @author yx200404 * * 2011-8-22 */ public class GWTController extends RemoteServiceServlet implements Controller, ServletConfigAware,ServletContextAware { /** * */ private static final long serialVersionUID = 2275269119904991518L; /* */ private ServletContext servletContext; @Override public void setServletConfig(ServletConfig arg0) { try { super.init(arg0); } catch (ServletException e) { e.printStackTrace(); } } @Override public void init(ServletConfig config) throws ServletException { super.init(config); } public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { doPost(request, response); return null; } @Override public void setServletContext(ServletContext servletContext) { this.servletContext = servletContext; } @Override public ServletContext getServletContext() { return servletContext; } }
3.改造GreetingService让它处于spring的监管下
打开GreetingService,然后去掉 @RemoteServiceRelativePath("greet") 注解.
打开GreetingServiceImpl,修改父类为我们刚刚写的Controller
public class GreetingServiceImpl extends GWTController implements GreetingService
然后给它添加一个注解 @Service("greetingService"),这个service是org.springframework.stereotype此包下的.
@Service("greetingService")public class GreetingServiceImpl extends GWTController implements GreetingService
4.修改web.xml
<web-app> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:spring/*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>gwtrpc</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>gwtrpc</servlet-name> <url-pattern>*.gwt</url-pattern> </servlet-mapping> <!-- Default page to serve --> <welcome-file-list> <welcome-file>GoogleMapV3.html</welcome-file> </welcome-file-list> </web-app>
5.修改GoogleMapV3.gwt.xml,添加servlet
<servlet class="com.yx.map.server.GreetingServiceImpl" path="/greetingService.gwt" />
6.给项目添加一个spring配置文件.具体做法是在项目中添加一个源包resources,然后在里面添加一个包spring,然后添加applicationContext.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation=" http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd" default-autowire="byName"> <context:component-scan base-package="com.yx" /> </beans>
7.为GXT注册新的servlet地址,添加以下代码到你自己的代码中就可以了
public static final String Greeting_SERVICE = "/greetingService.gwt"; public void onModuleLoad() { ServiceDefTarget endpoint = (ServiceDefTarget) greetingService; String moduleRelativeURL = Greeting_SERVICE; endpoint.setServiceEntryPoint(moduleRelativeURL); Registry.register(Greeting_SERVICE, greetingService); // 设置样式 GXT.setDefaultTheme(Theme.GRAY, true); //.....下面的代码不变
好了...重新启动下,看看效果是不是一样的呢?^^
过会再发个gxt配合Hibernate使用的方案.
http://www.nptpark.com
相关文章推荐
- 写了一个二叉树的完整实现
- 把一个数组的值存入二叉树中,然后进行3种方式的遍历(完整代码)
- 用string实现的一个完整的类,包含以下操作:重载运算符 > >,< < ,string模板类,fstream对二进制数据读写
- php中一个完整表单处理实现代码
- 一个开发者帐号在多台Mac上如何都能实现真机测试?
- ABAP--一个实现Search Help Exits的完整样例
- GuozhongCrawler实现一个完整爬虫
- !手把手教你实现一个完整的 Promise
- 看来,还真的需要一个完整测试用例
- 让我们一步一步实现一个完整的 String 类:构造、拷贝、赋值、移动和析构
- 如何使用jQuery+PHP+MySQL来实现一个在线测试项目
- 基于mina实现一个简单数据采集中间件的多客户端在线测试程序
- 一个完整的包命名空间定义实现的代码 -- 色色原创
- 完整类实现:构造,析构,遍历二叉树
- 一个完整托盘程序的实现
- 二叉树完整实现C++
- 如何用一个栈实现二叉树的螺旋遍历
- 一个计算机爱好者的不完整回忆(四十一)一次无聊的测试
- 用 javascript 实现 ping 一个主机,仅测试是否能够连接。
- 一个Java实现的简单的多个客户端聊天程序(未测试)