1 <properties>
2 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
3 <spring.version>4.1.0.RELEASE</spring.version>
4 </properties>
5
6 <dependency>
7 <groupId>org.springframework</groupId>
8 <artifactId>spring-webmvc</artifactId>
9 <version>${spring.version}</version>
10 </dependency>
11 <dependency>
12 <groupId>org.springframework</groupId>
13 <artifactId>spring-web</artifactId>
14 <version>${spring.version}</version>
15 </dependency>
浣跨敤springMVC鍒涘緩涓涓彲浠ヨ繑鍥濲SON鐨勬柟娉曪紝闇瑕佸涓嬩功鍐欙紝鍏抽敭瑕佷負(fù)鐗瑰畾鐨勬柟娉曟坊鍔?strong style="color: #ff0000; font-size: 13px; background-color: #eeeeee;">@ResponseBody錛屽皢榪斿洖鍊艱嚜鍔ㄨ漿鎹負(fù)JSON鏍煎紡錛屼綔涓虹浉搴旂殑鍐呭
1 @RequestMapping("/subCates")
2 public @ResponseBody List<Category> listSubCates(@Param Integer pId){
3 List<Category> cs = categoryService.listCategoryByPcid(pId);
4 return cs;
5 }
璇ユ敞瑙i渶瑕佸湪xxx-servlet.xml閰嶇疆涓紑鍚?br />1 <mvc:annotation-driven />
鍗曟槸濡傛榪樹笉澶燂紝緇忚繃璋冩煡錛宻pringMVC榪樹緷璧栦簡澶勭悊JSON鐨勭被搴揓ackson
1 <!-- JSON -->
2 <dependency>
3 <groupId>com.fasterxml.jackson.core</groupId>
4 <artifactId>jackson-core</artifactId>
5 <version>2.5.0</version>
6 </dependency>
7
8 <dependency>
9 <groupId>com.fasterxml.jackson.core</groupId>
10 <artifactId>jackson-databind</artifactId>
11 <version>2.5.0</version>
12 </dependency>
13
14 <dependency>
15 <groupId>org.codehaus.jackson</groupId>
16 <artifactId>jackson-mapper-asl</artifactId>
17 <version>1.9.13</version>
18 </dependency>
鏈漢鏈寮濮嬪彧渚濊禆浜唌apper鍜宑ore錛屾病鏈夋坊鍔燿atabind渚濊禆鎵嶅鑷翠簡406閿欒銆傝皟鏌ヤ箣鍚庡彂鐜幫紝鍏跺疄鍙渶瑕佹坊鍔燿atabind渚濊禆灝卞彲浠ヨВ鍐抽棶棰橈紝databind渚濊禆浜哻ore絳夐厤緗?img src ="http://www.tkk7.com/produ/aggbug/422480.html" width = "1" height = "1" />
]]>