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