import com.dalaoyang.entity.User;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author dalaoyang
* @Description
* @project springboot_learn
* @package com.dalaoyang.controller
* @email yangyang@dalaoyang.cn
* @date 2018/4/8
*/
@RestController
public class UserController {
//http://localhost:8080/json
@GetMapping(value = "/json",produces = MediaType.APPLICATION_JSON_VALUE)
public User index(){
User user = new User("dalaoyang", "26", "北京");
return user;
}
//http://localhost:8080/xml
@GetMapping(value = "/xml",produces = MediaType.APPLICATION_XML_VALUE)
public User XML(){
User user = new User("dalaoyang", "26", "北京");
return user;
}
}
![](https://user-gold-cdn.xitu.io/2018/4/8/162a48fd6ad65d1c?w=1596&h=280&f=jpeg&s=62022)
![](https://user-gold-cdn.xitu.io/2018/4/8/162a490392a33f5e?w=1706&h=398&f=jpeg&s=116960)