package com.xihuani.system.controller; 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.xihuani.system.model.User; import com.xihuani.system.service.UserService; @Controller @RequestMapping("api") public class SystemAPI { @Autowired private UserService userService; @RequestMapping(value = "user/{userId}", method=RequestMethod.GET) @ResponseBody public User getById(@PathVariable Integer userId) { return userService.findUser(userId); } @RequestMapping(value="user", method=RequestMethod.POST) @ResponseBody public String saveUser(@RequestBody User user) { userService.save(user); return "Saved user: " + user.getId(); } }