Spring4.0 Combat Rest Related

Source: Internet
Author: User

 PackageCom.paic.pay.merchant.web;ImportCom.paic.pay.merchant.entity.MerchantUser;ImportCom.paic.pay.merchant.exception.Error;Importcom.paic.pay.merchant.exception.UserNotFoundException;ImportCom.paic.pay.merchant.mapper.UserRegisterMapper;ImportCom.paic.pay.merchant.vo.Pizza;Importlombok.extern.slf4j.Slf4j;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.http.HttpStatus;Importorg.springframework.http.ResponseEntity;Importorg.springframework.web.bind.annotation.*;Importjavax.servlet.http.HttpServletRequest;ImportJava.util.UUID;/*** Created tangxin pc on 2017/1/17.*/@Slf4j @restcontroller@requestmapping (value= "/v1") Public classRegistercontroller {@AutowiredPrivateUserregistermapper Userregistermapper; /*** Merchant Registration *@return     */@PostMapping (Value= "/reg")     PublicString Reg () {return"Reg"; } @PostMapping (Value= "/cache")     Public voidCache (HttpServletRequest request) {LongDate =System.currenttimemillis (); String Threadindex= Request.getparameter ("Threadindex"); String URL=Request.getrequesturi (); Log.info ("url:{} date:{} threadindex:{}", Url,date,threadindex); } @GetMapping (Value= "/uuid")     PublicString uuid () {returnUuid.randomuuid (). toString (); } @GetMapping (Value= "/pizza")     PublicPizza Getpizza () {Pizza Pizza=NewPizza ("Chinese Pizza"); returnPizza; } @GetMapping (Value= "/getuser")     Publicmerchantuser Getmerchantuser (String userId) {merchantuser Merchantuser=Userregistermapper.getmerchantuser (userId); returnMerchantuser; } @GetMapping (Value= "/student")     Publicstring XML (String time) {Log.info ("Params:{}"ntime); return"<?xml version=\" 1.0\ "encoding=\" utf-8\ "?><student> Tang Xin </student>"; } @GetMapping (Value= "/getuser2")     PublicResponseentity<merchantuser>GetMerchantUser2 (String userId) {merchantuser Merchantuser=Userregistermapper.getmerchantuser (userId); Httpstatus Status= merchantuser!=NULL?HttpStatus.OK:HttpStatus.NOT_FOUND; return NewResponseentity<>(Merchantuser,status); } @GetMapping (Value= "/getuser3")     PublicResponseentity<?>GetMerchantUser3 (String userId) {merchantuser Merchantuser=Userregistermapper.getmerchantuser (userId); if(merchantuser==NULL) {Error Error=NewError (4, "User [" +userid+ "] does not exist"); return NewResponseentity<>(Error,httpstatus.not_found); }        return NewResponseentity<>(Merchantuser,httpstatus.ok); }    /*** When the query result is NULL, an exception is thrown by the exception handler return code *@paramUserId *@returnnormal return: {"userId": +, "UserName": Zhang San} * Exception returned: {"Code": 4, "message": "User [16] does not exist"}*/@GetMapping (Value= "/getuser4")     PublicResponseentity<merchantuser>getMerchantUser4 (String userId) {merchantuser Merchantuser=Userregistermapper.getmerchantuser (userId); if(merchantuser==NULL){Throw Newusernotfoundexception (userId);} return NewResponseentity<>(Merchantuser,httpstatus.ok); }    /*** Exception Processor *@paramE *@return     */@ExceptionHandler (usernotfoundexception.class)     PublicResponseentity<error>Usernotfound (usernotfoundexception e) {String userId=E.getuserid (); Error Error=NewError (4, "User [" +userid+ "] does not exist"); return NewResponseentity<>(Error,httpstatus.not_found); }}

Spring4.0 Combat Rest Related

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.