好家伙,写后端,这多是一件美逝.
关于这个项目的代码前面的博客有写
我的第一个独立项目 - 随笔分类 - 养肥胖虎 - 博客园 (cnblogs.com)
现在,我们登陆进去了,我开始和敌人战斗,诶,打到一百分了,我现在要把这个分数保存起来
随便写一个测试样例
<template> <div> <div ref="stage"></div> <button @click="http">网络请求测试</button> </div> </template> <script> import { canvas, main_1 } from "panghu-planebattle-esm" import bus from '../js/eventBus' export default { data() { return { player: { id:'', loginName: 123456, life: 100, score: score, }, } }, methods:{ http(){ setInterval(() => { this.axios.post('http://localhost:3312/sys-user/update', this.player) .then((resp) => { console.log("this is update", resp); let data = resp.data; // if (data.success) { console.log({ message: '修改成功', type: 'success' }); } }) }, 5000) } },复制
(确实是非常朴实无华的测试样例)
来到controller类中添加接口
@PostMapping("update") public CommonResp update(@RequestBody SysUserUpdateReq req){ // zxcv1234 CommonResp resp = new CommonResp<>(); sysUserService.update(req); return resp; }复制
因为这个我们只做对数据的更新,所以只用LoginName,life,score就可以了
package com.wulaoda.loginhouduan.req; public class SysUserUpdateReq { private String LoginName; private int life; private int score; public String getLoginName() { return LoginName; } public void setLoginName(String loginName) { LoginName = loginName; } public int getLife() { return life; } public void setLife(int life) { this.life = life; } public int getScore() { return score; } public void setScore(int score) { this.score = score; } @Override public String toString() { return "SysUserUpdateReq{" + "LoginName='" + LoginName + '\'' + ", life=" + life + ", score=" + score + '}'; } }复制
这里Mybatis-plus提供的update方法
嘶,参数看不懂
然后,改怎么写啊...不会啊...
必应我来了
mybatis-plus入门学习-BaseMapper - 掘金 (juejin.cn)
mybatis-plus update更新操作的三种方式_mybatisplus的uodate_波神小波的博客-CSDN博客
直接就对着抄
//数据更新 @Override public SysUserUpdateResp update(SysUserUpdateReq req){//重写 //网上的例子 // LambdaUpdateWrapper<User> lambdaUpdateWrapper = new LambdaUpdateWrapper<>(); // lambdaUpdateWrapper.eq(User::getName, "rhb").set(User::getAge, 18); // Integer rows = userMapper.update(null, lambdaUpdateWrapper); LambdaUpdateWrapper<SysUserEntity> wrapper1 = new LambdaUpdateWrapper<>(); wrapper1.eq(SysUserEntity::getLoginName, req.getLoginName()).set(SysUserEntity::getLife, req.getLife()); sysUserMapper.update(null,wrapper1); return null; }复制
前端点下按钮,开始测试,
数据成功修改