Spring Boot-11 Controller Controllers

Source: Internet
Author: User


 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.