// Path: src/main/java/cn/com/chenyixiao/rrs/entity/User.java
// @Entity
// @Table(name = "user", catalog = "rrs")
// public class User implements java.io.Serializable {
// 
// 	private long id;
// 	private String name;
// 
// 	public User() {
// 	}
// 
// 	public User(long id) {
// 		this.id = id;
// 	}
// 
// 	public User(long id, String name) {
// 		this.id = id;
// 		this.name = name;
// 	}
// 
// 	@Id
// 	@Column(name = "id", unique = true, nullable = false)
// 	public long getId() {
// 		return this.id;
// 	}
// 
// 	public void setId(long id) {
// 		this.id = id;
// 	}
// 
// 	@Column(name = "name")
// 	public String getName() {
// 		return this.name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// }
// 
// Path: src/main/java/cn/com/chenyixiao/rrs/service/UserService.java
// public interface UserService {
// 	
// 	public void addUser(User user);
// 	public void updateUser(User user);
// 	public User getUser(Long id);
// 	public List<User> getAllUsers();
// 	public void deleteUser(Long id);
// 	public void deleteAllUsers();
// 	
// 	public Long count();
// 	
// 	public User getUserByName(String name);
// }


import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.gson.Gson;
import cn.com.chenyixiao.rrs.entity.User;
import cn.com.chenyixiao.rrs.service.UserService;
package cn.com.chenyixiao.rrs.controller;





@Controller
@RequestMapping(produces="application/json;charset=UTF-8", 
		consumes="application/json;charset=UTF-8")
public class UserController {

	@Autowired
	private UserService userService;
	
	@ResponseBody
	@RequestMapping(value="/user", method = RequestMethod.POST)
	public String addUser(@RequestBody User user) {
		userService.addUser(user);
		String ret = new Gson().toJson(
				userService.getUserByName(user.getName()));
		return ret;
	}
	
	@ResponseBody
	@RequestMapping(value="/user/{id}", method = RequestMethod.GET)
	public String getUser(@PathVariable long id) {
		User user = userService.getUser(id);
		return new Gson().toJson(user);
	}
	
	@ResponseBody
	@RequestMapping(value="/user", method = RequestMethod.GET)
	public String getUserList() {
// Path: src/main/java/cn/com/chenyixiao/rrs/entity/User.java
// @Entity
// @Table(name = "user", catalog = "rrs")
// public class User implements java.io.Serializable {
// 
// 	private long id;
// 	private String name;
// 
// 	public User() {
// 	}
// 
// 	public User(long id) {
// 		this.id = id;
// 	}
// 
// 	public User(long id, String name) {
// 		this.id = id;
// 		this.name = name;
// 	}
// 
// 	@Id
// 	@Column(name = "id", unique = true, nullable = false)
// 	public long getId() {
// 		return this.id;
// 	}
// 
// 	public void setId(long id) {
// 		this.id = id;
// 	}
// 
// 	@Column(name = "name")
// 	public String getName() {
// 		return this.name;
// 	}
// 
// 	public void setName(String name) {
// 		this.name = name;
// 	}
// 
// }
// 
// Path: src/main/java/cn/com/chenyixiao/rrs/service/UserService.java
// public interface UserService {
// 	
// 	public void addUser(User user);
// 	public void updateUser(User user);
// 	public User getUser(Long id);
// 	public List<User> getAllUsers();
// 	public void deleteUser(Long id);
// 	public void deleteAllUsers();
// 	
// 	public Long count();
// 	
// 	public User getUserByName(String name);
// }


// Path: src/main/java/cn/com/chenyixiao/rrs/controller/UserController.java
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.gson.Gson;
import cn.com.chenyixiao.rrs.entity.User;
import cn.com.chenyixiao.rrs.service.UserService;

package cn.com.chenyixiao.rrs.controller;





@Controller
@RequestMapping(produces="application/json;charset=UTF-8", 
		consumes="application/json;charset=UTF-8")
public class UserController {

	@Autowired
	private UserService userService;
	
	@ResponseBody
	@RequestMapping(value="/user", method = RequestMethod.POST)
	public String addUser(@RequestBody User user) {
		userService.addUser(user);
		String ret = new Gson().toJson(
				userService.getUserByName(user.getName()));
		return ret;
	}
	
	@ResponseBody
	@RequestMapping(value="/user/{id}", method = RequestMethod.GET)
	public String getUser(@PathVariable long id) {
		User user = userService.getUser(id);
		return new Gson().toJson(user);
	}
	
	@ResponseBody
	@RequestMapping(value="/user", method = RequestMethod.GET)
	public String getUserList() {
		List<User> userList = userService.getAllUsers();