PackageCom.sample.smartmap.controller;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.http.MediaType;ImportOrg.springframework.stereotype.Controller;ImportOrg.springframework.ui.Model;Importorg.springframework.web.bind.annotation.GetMapping;Importorg.springframework.web.bind.annotation.PathVariable;Importorg.springframework.web.bind.annotation.PostMapping;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.ResponseBody;ImportCom.sample.smartmap.entity.User;ImportCom.sample.smartmap.service.UserService;/*** URL map to method **/@Controller @requestmapping ("/user4") Public classSample34controller {@Autowired userservice userservice; @GetMapping ("/" ) Public@ResponseBody String Index () {return"Hell"; } /*** Client requests must contain Application/json before processing *@return */@GetMapping (Value= "/all1.json", consumes = "Application/json") @ResponseBody PublicUser Forjson () {returnUserservice.getuserbyid (1l); } @GetMapping (Path= "/user/{userid}.json", produces =mediatype.application_json_utf8_value) @ResponseBody PublicUser getUser (@PathVariable Long userId, model model) {returnUserservice.getuserbyid (userId); } @GetMapping (Path= "/update.json", params = "Action=save") @ResponseBody Public voidSaveuser () {System.out.println ("Call Save"); } @GetMapping (Path= "/update.json", params = "Action=update") @ResponseBody Public voidUpdateUser () {System.out.println ("Call Update"); } }
Spring Boot-11 Controller Controllers