Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.gong.illidan.rest.controller; import com.gong.illidan.dao.model.User; import com.gong.illidan.service.UserService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; /** * * @author gongbenkai */ @RestController @RequestMapping(value = "/api") public class UserController { private final Logger log = LoggerFactory.getLogger(UserController.class); @Autowired private UserService userService; /** * GET /users -> get all the users */ @RequestMapping(value = "/test", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<User> test() { log.info("REST request to test"); return new ResponseEntity<>(userService.getUser(1), HttpStatus.OK); } }