ExtJS 4的MVC框架
ExtJS 4引入MVC架构,可以用来创建ExtJS应用程序,与经典的Ext.onReady回调方式很不相同。
MVC架构
在开发ExtJS应用时,往往习惯于把所有JavaScript代码编写在单个文件中,生产环境下的应用通常都比较复杂,可能包括了面板、表单、表格、布局、模型、存储等多种组件的组合。大量的组件代码导致JS文件急剧膨胀,难以维护,因此很有必要根据职责的不同把代码划…
阅读全文
11 years ago
0
SpringMVC知识集锦
基于仿冒的SpringMVC测试用例示意
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
package cc.gmem.demo.ctrl; import static org.junit.Assert.*; import javax.inject.Inject; import net.greenmemory.commons.lang.StringUtils; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.LoggerFactory; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.transaction.TransactionConfiguration; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import com.fasterxml.jackson.databind.ObjectMapper; @RunWith ( SpringJUnit4ClassRunner.class ) @ContextConfiguration ( locations = { "/spring-classgen-disabled.xml", "/spring-mvc.xml" } ) @TransactionConfiguration ( transactionManager = "txManager", defaultRollback = true ) public class SpringMVCControllerTest { private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger( SpringMVCControllerTest.class ); @Inject private RequestMappingHandlerAdapter handlerAdapter; @Inject private RequestMappingHandlerMapping handlerMapping; @Inject private SessionFactory sf; @Inject private ObjectMapper om; private MockHttpServletRequest request; private MockHttpServletResponse response; @Before @Transactional public void setUp() { request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); Session sess = sf.getCurrentSession(); } @Test @Transactional public void testController() throws Exception { request.setRequestURI( "/uri/" ); //设置请求的URI Object handler = handlerMapping.getHandler( request ).getHandler(); //获取Handler对象(就是控制器类) handlerAdapter.handle( request, response, handler ); //转发给Handler处理,并获取响应 String contentType = response.getContentType(); String json = response.getContentAsString(); assertTrue( StringUtils.containsIgnoreCase( contentType, "json" ) ); assertTrue( StringUtils.containsIgnoreCase( contentType, "utf-8" ) ); } } |
常用问题
强制产生JSON格式的结果
配置 @RequestMapping( produces = "application/json" )
SpringMVC 设置 /* 过滤全部,导致JSP无法显示的问题
找不到控制器类的问题:No mapping found for HTTP request with URI
- 注意URL拦截的前置部分,如/admin,不要再控制器的映射路径中体现,例如地址/admin/user在控制器中直接配: /user
使用…
12 years ago
0
Spring MVC 3.0学习笔记
Spring MVC框架简介
Spring MVC 3.0新特性
- 支持REST风格的URL
- 添加更多注解,可完全注解驱动
- 引入HTTP输入输出转换器(HttpMessageConverter)
- 和数据转换、格式化、验证框架无缝集成
- 对静态资源处理提供特殊支持 更加灵活…
12 years ago
0