好家伙,寫后端,這多是一件美逝.
關(guān)于這個項目的代碼前面的博客有寫?
我的第一個獨立項目 - 隨筆分類 - 養(yǎng)肥胖虎 - 博客園 (cnblogs.com)
?
現(xiàn)在,我們登陸進去了,我開始和敵人戰(zhàn)斗,誒,打到一百分了,我現(xiàn)在要把這個分數(shù)保存起來
?文章來源地址http://www.zghlxwxcb.cn/news/detail-427347.html
?
1.前端先把測試樣例寫好
?隨便寫一個測試樣例
<template>
<div>
<div ref="stage"></div>
<button @click="http">網(wǎng)絡(luò)請求測試</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)
}
},
?
?(確實是非常樸實無華的測試樣例)
?
?
2.隨后我們來到后端
來到controller類中添加接口
?
@PostMapping("update")
public CommonResp update(@RequestBody SysUserUpdateReq req){
// zxcv1234
CommonResp resp = new CommonResp<>();
sysUserService.update(req);
return resp;
}
?
?
3.在req文件下添加一個SysUserUpdateReq類
因為這個我們只做對數(shù)據(jù)的更新,所以只用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 +
'}';
}
}
?
4.編寫業(yè)務(wù)
這里Mybatis-plus提供的update方法
嘶,參數(shù)看不懂
?然后,改怎么寫啊...不會啊...
必應(yīng)我來了
mybatis-plus入門學習-BaseMapper - 掘金 (juejin.cn)
mybatis-plus update更新操作的三種方式_mybatisplus的uodate_波神小波的博客-CSDN博客
直接就對著抄
?
//數(shù)據(jù)更新
@Override
public SysUserUpdateResp update(SysUserUpdateReq req){//重寫
//網(wǎng)上的例子
// 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;
}
?
前端點下按鈕,開始測試,
?數(shù)據(jù)成功修改文章來源:http://www.zghlxwxcb.cn/news/detail-427347.html
?
到了這里,關(guān)于我的第一個項目(十二) :分數(shù)和生命值的更新(后端增刪查改的"改")的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!