springMVC--(講解6)springmvc輸出json格式

#1.添加jar包spring

<!-- jackson -->
	<dependency>
    	<groupId>com.fasterxml.jackson.core</groupId>
    	<artifactId>jackson-databind</artifactId>
    	<version>2.8.3</version>
	</dependency>	
	<dependency>
    	<groupId>org.codehaus.jackson</groupId>
    	<artifactId>jackson-mapper-asl</artifactId>
    	<version>1.9.13</version>
	</dependency>

依賴包以下:
jackson-databind-2.8.3.jar
jackson-annotations-2.8.0.jar
jackson-core-2.8.3.jar
jackson-mapper-asl-1.9.13.jar
jackson-core-asl-1.9.13.jar
#2.springmvc配置
添加註解驅動mvc

<!-- mvc註解驅動 -->
	<mvc:annotation-driven/>

#3.controller層app

@RestController
public class UserController {
	
	@Autowired
	private UserService userService;
	
	/**
	 * 獲取用戶列表
	 */
	@RequestMapping(value="/userList",method= RequestMethod.GET)
	public ResultObject getUserList() {
		ResultObject ro = null;
		try {
			ro = userService.getUserList();
		} catch (Exception e) {
			ro = Utils.processException();
		}
		return ro;
	}
}
相關文章
相關標籤/搜索