File tree Expand file tree Collapse file tree 4 files changed +31
-2
lines changed Expand file tree Collapse file tree 4 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 52
52
第三种:/*,这样配置是不对的,使用这种配置,最重要转发到一个jsp页面时,仍然会由DispatcherServlet解析jsp地址, 不能根据jsp页面找打Handler,会报错 -->
53
53
<url-pattern >*.action</url-pattern >
54
54
</servlet-mapping >
55
+
56
+ <!-- 配置springmvc的前端控制器DispatcherServlet,REST配置 -->
57
+ <servlet >
58
+ <servlet-name >springmvc_rest</servlet-name >
59
+ <servlet-class >org.springframework.web.servlet.DispatcherServlet</servlet-class >
60
+
61
+ <!-- contextConfigLocation是配置springmvc加载的配置文件(配置处理器映射器、适配器等) 如果不配置contextConfigLocation,则默认加载的是/WEB-INF/springmvc-servlet.xml -->
62
+ <init-param >
63
+ <param-name >contextConfigLocation</param-name >
64
+ <param-value >classpath:spring/springmvc.xml</param-value >
65
+ </init-param >
66
+ </servlet >
67
+
68
+ <servlet-mapping >
69
+ <servlet-name >springmvc_rest</servlet-name >
70
+ <url-pattern >/</url-pattern >
71
+ </servlet-mapping >
55
72
56
73
</web-app >
Original file line number Diff line number Diff line change @@ -24,8 +24,7 @@ function requestJson(){
24
24
alert (data .name );
25
25
}
26
26
27
- });
28
-
27
+ });
29
28
30
29
}
31
30
// 请求key/value,输出是json
Original file line number Diff line number Diff line change 133
133
<property name =" maxUploadSize" value =" 5242880" />
134
134
<property name =" defaultEncoding" value =" utf-8" />
135
135
</bean >
136
+
137
+ <!-- 静态资源解析,包括js,css,img... -->
138
+ <mvc : resources location =" /js/" mapping =" /js/**" ></mvc : resources >
139
+ <mvc : resources location =" /img/" mapping =" /img/**" ></mvc : resources >
136
140
</beans >
Original file line number Diff line number Diff line change 12
12
import org .springframework .validation .BindingResult ;
13
13
import org .springframework .validation .ObjectError ;
14
14
import org .springframework .validation .annotation .Validated ;
15
+ import org .springframework .web .bind .annotation .PathVariable ;
15
16
import org .springframework .web .bind .annotation .RequestBody ;
16
17
import org .springframework .web .bind .annotation .RequestMapping ;
17
18
import org .springframework .web .bind .annotation .RequestParam ;
@@ -196,5 +197,13 @@ public String editItemsQueryResult(ItemsQueryVo itemsQueryVo)
196
197
197
198
return itemsCustom ; //由于@ResponseBody注解,将itemsCustom转成json格式返回
198
199
}
200
+
201
+ //查询商品信息,输出json,使用RESTful
202
+ @ RequestMapping ("/itemsView/{id}" )
203
+ public @ ResponseBody ItemsCustom itemsView (@ PathVariable ("id" ) Integer id ) throws Exception {
204
+ ItemsCustom itemsCustom = itemsService .findItemsById (id );
205
+ return itemsCustom ;
206
+ }
207
+
199
208
200
209
}
You can’t perform that action at this time.
0 commit comments