【SpringBoot中SpringMVC服务之处理post请求】

一.AccountController

复制代码
@RestController
@RequestMapping("account")
public class AccountController extends AbstractGameCenterServerController {

    @Autowired
    private AccountRegisterService accountRegisterService;
    @Autowired
    private AccountService accountLoginService;

    @PostMapping("register")
    public Object registerAccount(@RequestBody AccountRegisterRequest param) throws Exception {
        AccountEntity account = new AccountEntity();
        account.setUsername(param.getUsername());
        account.setPassword(param.getPassword());
        accountRegisterService.accountRegister(account);
        AccountLoginResponse voLoginSuccess = accountLoginService.getLoginResponse(account);
        return responseSuccess(voLoginSuccess);
    }


    @PostMapping("login")
    public Object loginAccount(@RequestBody AccountLoginRequest loginParam) throws Exception {
        AccountEntity account = accountLoginService.login(loginParam);
        AccountLoginResponse loginSuccess = accountLoginService.getLoginResponse(account);
        return responseSuccess(loginSuccess);
    }
}

1.RestController+RequestMapping

2.PostMapping + @RequestBody

相关推荐
程序员小八7779 小时前
Java 快速转 Go
java·python·golang
职场的momo9 小时前
11个后端与AI岗位同时开放:Java、网关、推理优化怎么匹配
java·开发语言·人工智能
罗超驿9 小时前
SpringMVC 请求参数接收详解|单个参数、多参数、对象参数、@RequestParam参数重命名
java·后端·postman·javaee
古法安卓10 小时前
Android-epoll原理详解
android·java·android studio
fireworks9910 小时前
接口鉴权(401与403)
java·后端
wear工程师11 小时前
线程池里的异常去哪了?execute 和 submit 不是一回事
java
孔明click3311 小时前
别人绕过我的网关直接调用资源服务怎么办?使用 Sa-Token 解决:网关转发鉴权、RPC调用鉴权
java·sa-token·springboot·权限·权限认证
吴声子夜歌11 小时前
Java面试——设计模式(一)
java·设计模式·面试
半亩码田11 小时前
C#转Python第3.6篇:Python 的 @property 比 C# 的 get/set 更灵活
java·python·c#
wno70411 小时前
Spring Boot中使用Servlet
spring boot·后端·servlet