SpringBoot接收前端資料的幾種常用方式

2021-10-07 03:32:55 字數 1061 閱讀 5527

addpost()  else })}

}

public respbean addposition(@requestbody position position) else

}修改操作時,json物件的轉化是一樣的,同post請求,使用@requestbody註解。

doeditpost() 

})}

public respbean editpostbyid(@requestbody position position) else

}實現刪除操作一般需要乙個id即可,此時可以在url上將id傳到後台即可,不需要通過json的形式傳值。後台接收使用@pathvariable註解。

handledelete(index, data) ).then(() => 

})}).catch(() => );

});}

public respbean deletepostbyid(@pathvariable integer id) else

}實現批量刪除需要獲得要刪除記錄的所有id,可以存放在陣列中。

前台可以直接封裝乙個id陣列傳到後台,在資料庫進行批量操作。

//批量刪除前台

handlemanydelete() ).then(() => )

this.deleterequest("/system/basic/post/many" + ids).then(resp =>

})}).catch(() => );

});}

//批量刪除後台控制層

public respbean deletemanypost(integer ids) else

}

//批量刪除資料庫操作,使用的mybatis。

delete from position

where id in (#)

Springboot常用接收資料方式

通常資料產生後需要傳送到管理平台進行檢視。產生傳送一般在下位機或者是某個程式中,整合資料後通過http方式或者是rabbitmq方式,上傳至管理平台。http和rabbitmq的區別,這裡不贅述。本章主要講http的get和post請求。因為 大多數是有很多屬性引數的。所以基本上傳方式是使用json...

springboot接收excel資料檔案去重

set names utf8mb4 set foreign key checks 0 table structure for student drop table if exists student create table student id int 11 not null comment 學號...

spring boot中post請求接收引數

spring boot遇坑記 引數直接寫long id一直報錯。調整為long id後 拿到的結果一直是null。引數需要加 requestbody 如只傳乙個id,必須要封裝到乙個物件中,可以用jsonobject 也可以自定義乙個param物件。city public city city req...