【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

相关推荐
咖啡八杯6 分钟前
GoF设计模式——策略模式
java·后端·spring·设计模式
java小白小5 小时前
SpringBoot(01): 初识SpringBoot,从Spring的痛点说起
spring boot
用户128526116028 小时前
我把祖传Java项目重构后,接口响应从3s砍到了200ms,只改了这几行代码
java
Linsk8 小时前
组件 = 模板 + 业务逻辑
java·前端·vue.js
星沉远浦9 小时前
用Gemini高效解决Java代码报错难以定位的问题
java
用户31693538118312 小时前
如何从零编写一个 Spring Boot Starter
spring boot
用户2986985301412 小时前
Word 文档字符级格式化:Java 实现方案详解
java·后端
笨鸟飞不快13 小时前
从单个服务到集群:一次完整的性能排查复盘
java·前端
荣码13 小时前
用Streamlit给AI应用套个界面,10行代码出Web页面
java·python
SamDeepThinking13 小时前
Java微服务练习方式
java·后端·微服务