Oracle基础笔记十二
2014-12-23 10:30
316 查看
Restlet2 + Spring3 配置如下,希望能对大家有用
Restlet : restlet-jee-2.0.3 注意是jee版本
Spring : 3.0.4.RELEASE
web.xml
applicationContext-restlet.xml
IndexResource.java
GameTypeResource.xml
SpringBeanRouter用到的是Spring的BeanNameUrlHandlerMapping,将url映射成bean
对于要使用基于restlet注解(@Get @Put @Post @Delete)配置,一定要直接继承ServerResource
对于路径的匹配模式还需要研究下
Restlet : restlet-jee-2.0.3 注意是jee版本
Spring : 3.0.4.RELEASE
web.xml
<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>restlet</servlet-name> <servlet-class> org.restlet.ext.spring.RestletFrameworkServlet </servlet-class> <init-param> <param-name>targetRestletBeanName</param-name> <param-value>webApp</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>restlet</servlet-name> <url-pattern>/resource/*</url-pattern> </servlet-mapping>
applicationContext-restlet.xml
<bean id="webApp" class="org.restlet.Application"> <property name="root" ref="root" /> </bean> <bean name="root" class="org.restlet.ext.spring.SpringBeanRouter"/> <alias name="indexResource" alias="/index.html"/> <alias name="gameTypeResource" alias="/admin/gametypes/{action}"/> <bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPath" value="/WEB-INF/page/" /> <property name="freemarkerSettings"> <props> <prop key="template_update_delay">0</prop> <prop key="default_encoding">UTF-8</prop> <prop key="locale">zh_CN</prop> </props> </property> </bean>
IndexResource.java
@Service @Scope("prototype") public class IndexResource extends ServerResource { @Autowired protected FreeMarkerConfigurer freemarkerConfig; @Autowired private GameTypeManager gameTypeManager; @Get("html") public Representation index() { List<GameType> gameTypeList = gameTypeManager.findListByRoot(GameTypeAttribute.Standard); Set<FlashGame> hotGames = gameTypeManager.getGameTypeByName("推荐游戏").getGames(); final Map<String, Object> dataModel = new TreeMap<String, Object>(); dataModel.put("gameTypeList", gameTypeList); dataModel.put("hotGames", hotGames); return new TemplateRepresentation("index.html", freemarkerConfig.getConfiguration(), dataModel, MediaType.TEXT_HTML); } }
GameTypeResource.xml
@Service @Scope("prototype") public class GameTypeResource extends ServerResource { @Autowired protected FreeMarkerConfigurer freemarkerConfig; @Autowired private GameTypeManager gameTypeManager; private String action; private int pageNum = 1; @Get("html") public Representation represent() { if (StringUtils.isNotEmpty((String) getRequest().getAttributes().get("action"))) { action = (String) getRequest().getAttributes().get("action"); } if (StringUtils.isNotEmpty((String) getRequest().getAttributes().get("pageNum"))) { pageNum = Integer.valueOf(((String) getRequest().getAttributes().get("pageNum"))); } if ("list".equals(action)) { return list(); } else if ("add".equals(action)) { return add(); } else { return list(); } } public Representation list() { PageBean pageBean = new PageBean(); pageBean.setPageNum(pageNum); pageBean.setMaxResults(100); List<GameType> gameTypes = gameTypeManager.getAll(pageBean); final Map<String, Object> dataModel = new TreeMap<String, Object>(); dataModel.put("gameTypes", gameTypes); dataModel.put("pageNum", pageNum); return new TemplateRepresentation("admin/gametypes.html", freemarkerConfig.getConfiguration(), dataModel, MediaType.TEXT_HTML); } public Representation add() { List<GameType> gameTypes = gameTypeManager.findListByAttribute(GameTypeAttribute.Standard); final Map<String, Object> dataModel = new TreeMap<String, Object>(); dataModel.put("gameTypes", gameTypes); return new TemplateRepresentation("admin/gametype_add.html", freemarkerConfig.getConfiguration(), dataModel, MediaType.TEXT_HTML); } @Post public Representation acceptRepresentation(Representation entity) throws ResourceException { Form form = new Form(entity); GameType gameType = new GameType(); gameType.setName(form.getFirstValue("name")); if (!StringUtils.isEmpty(form.getFirstValue("parentId"))) { Long parentId = Long.valueOf(form.getFirstValue("parentId")); GameType parent = gameTypeManager.get(parentId); if (parent != null) { gameType.setParent(parent); } } gameType.setGameTypeAttribute(GameTypeAttribute.Standard); gameTypeManager.saveByName(gameType); return get(); } @Put public Representation storeRepresentation(Representation entity) throws ResourceException { Form form = new Form(entity); GameType gameType = new GameType(); gameType.setName(form.getFirstValue("name")); if (!StringUtils.isEmpty(form.getFirstValue("parentId"))) { Long parentId = Long.valueOf(form.getFirstValue("parentId")); GameType parent = gameTypeManager.get(parentId); if (parent != null) { gameType.setParent(parent); } } gameType.setGameTypeAttribute(GameTypeAttribute.Standard); gameTypeManager.saveByName(gameType); return get(); } @Delete public Representation removeRepresentations(Representation entity) throws ResourceException { Form form = new Form(entity); if (!StringUtils.isEmpty(form.getFirstValue("id"))) { Long id = Long.valueOf(form.getFirstValue("id")); gameTypeManager.removeById(id); } return get(); } }
SpringBeanRouter用到的是Spring的BeanNameUrlHandlerMapping,将url映射成bean
对于要使用基于restlet注解(@Get @Put @Post @Delete)配置,一定要直接继承ServerResource
对于路径的匹配模式还需要研究下
相关文章推荐
- oracle基础知识(笔记)
- Oracle 基础笔记4
- 初学Oracle的笔记(1)——基础内容(实时更新中..)
- Oracle基础学习笔记(三)(Import, Export, SQL Loader)
- Oracle基础学习笔记(二)(Index)
- oracle 的面向服务的基础架构(SOA)研讨会(济南) 的一点笔记
- Oracle基础学习笔记(1)
- oracle基础笔记-如果不是DBA,作为一个程序设计人员,特别是要使用Oracle的程序人员.非常有必要了解以下
- Oracle笔记 十二、PL/SQL 面向对象oop编程
- Oracle基础学习笔记(五) (PL/SQL)
- Oracle 基础笔记 5
- oracle基础知识(笔记)
- Oracle基础学习笔记
- Oracle笔记 十二、PL/SQL 面向对象oop编程
- 原创:oracle PL/SQL编程基础 下(十二)
- Oracle 基础笔记 3
- ORACLE笔记(二):SQL基础收集
- Java培训笔记十二(中信的Java基础归纳)
- 重新整理后的Oracle OAF学习笔记——3.应用构建基础之实现模型
- 重新整理后的Oracle OAF学习笔记——4.应用构建基础之实现视图