-
json轉字串,會把null轉成"",所以當向后臺傳物件時,必須將外鍵從""改為null,不然后端無法轉換json
-
post提交了字串,而后臺用了@requestBody注解,應該提交物件
[http-nio-80-exec-5] WARN o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]
前端請求傳Json物件則后端使用@RequestParam;
前端請求傳Json物件的字串則后端使用@RequestBody,
-
如果存的是字串,json物件必須轉換成字串,不然存盤的是Object object
-
select * from user where role='2sad'
資料庫中int型別的欄位,傳入String型別的資料,會截取字串進行查找
-
cookie:將"password"的時間設定為過去,也就是把它洗掉,期待讀出空,但讀出了錯誤的資訊(很長一條)
原因是存入了User物件,里面包含了password欄位,所以讀出的錯誤資訊來自于User物件,
所以將“=”寫成“==”,如:document.cookie = key + "==" + val + ";expires=" + date.toUTCString();
-
element時區問題,element的時間是世界時間,資料庫存的是中國時間,世界時間慢8小時,所以頁面顯示早一天
解決方法:顯示前,將時間轉化
// 自定義格式化時間,避免時區誤差
Vue.prototype.formatterTime = (time) => {
const date = new Date(time);
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
/*const hour = date.getHours()
const minutes = date.getMinutes()
const seconds = date.getSeconds()
const dateTime = year + '-' + month + '-' + day + ' ' + checkLength(hour) + ':' + checkLength(minutes) + ':' + checkLength(seconds)*/
const dateTime = year + '-' + month + '-' + day;
return dateTime;
}
?
// 時分秒為個位時,前面加0
function checkLength (str){
str = str.toString();
if (str.length < 2) {
str = '0' + str;
}
return str;
}
-
js陣列賦值,改變其中一個,另外一個陣列也會改變,vue的資料系結
解決方法:把要賦值的資料轉成json字串,再轉成json物件賦值(必須新建一個物件,不然都是指向同一個記憶體地址)
let list = JSON.parse(JSON.stringify(this.tableData));
-
匯出表格,里面的嵌套屬性無法識別
解決方法:添加新的鍵值對
exportXlsx() {
let tHeader = ['學號','姓名','性別','專業','年級','二級基層黨組織','黨支部'];
let filterVal = ['sno','name','sex','major','grade','secondParty','partyBranch'];
let list = JSON.parse(JSON.stringify(this.tableData));
for (let i = 0; i < list.length; i++) {
list[i].sex=list[i].sex == '0' ? '男' : '女';
list[i].secondParty=list[i].user.secondParty.name;
list[i].partyBranch=list[i].user.partyBranch.name;
}
let name = '發展黨員名單';
this.exportExcel(tHeader,filterVal,list,name);
},
-
element的DatePicker日期(范圍)選擇器賦值不成功,發現model上的資料發生改變,而頁面上的視圖資料沒有改變
解決方法:使用this.$set();
陣列使用示列:this.$set(arr, index, val),
物件使用示例:this.$set( obj, key, val).
-
前端插入資料時,用到剛添加的物件的id,但id為資料庫自增的,獲取不到
解決方法:在xml里加一個主鍵自增
<insert id="insert" keyProperty="id" useGeneratedKeys="true" parameterType="User">
insert into user(username,password,state,role,second_party,party_branch,updatetime)
values(#{username},#{password},#{state},#{role.id},#{secondParty.id},#{partyBranch.id},sysdate())
</insert>
@PostMapping("/add")
public ResultMessage add(@RequestBody User user) {
logger.debug("enter add");
logger.debug("user=" + user);
boolean result = service.add(user);
//logger.debug("userId="+user.getId()); 此時的user里有id
ResultMessage resultMessage;
if (result) {
resultMessage = new ResultMessage(true, user, 0, "添加成功");
} else {
resultMessage = new ResultMessage(false, null, 0, "添加失敗");
}
return resultMessage;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/299077.html
標籤:其他
