专注app软件定制开发前台传送后端数据的几种方式


1.发送get专注app软件定制开发请求将参数通过?拼接在url后面

  1. $.ajax({
  2.         url: "/order/userPage?page="+page+"&pageSize="+pageSize,    //请求的url地址  
  3.         cache: "false",   //设置为false专注app软件定制开发将不会从浏览器中加载请求信息
  4.         async: "true",    //true所有请求均为异步请求
  5.         dataType: "json", //请求返回数据的格式
  6.         type:"get",      //请求方式
  7. 上面等同于==>>
  8. async initData(){
  9. paging: {
  10. page: 1,
  11. pageSize: 5
  12. }
  13. const res = await orderPagingApi(this.paging)
  14. }
  15. function orderPagingApi(data) {
  16. return $axios({
  17. 'url': '/order/userPage',
  18. 'method': 'get',
  19. //请求参数
  20. params: {...data}
  21. })
  22. 上面等同于==>>
  23. async initData(){
  24. paging: {
  25. page: 1,
  26. pageSize: 5
  27. }
  28. const res = await orderPagingApi(this.paging)
  29. }
  30. function orderPagingApi(data) {
  31. return $axios({
  32. 'url': '/order/userPage',
  33. 'method': 'get',
  34. 'data': data
  35. })
后端接收参数
  1. @GetMapping("/order/userPage")
  2. @ResponseBody
  3. public R<Page> userPage(Integer page,Integer pageSize){}
  4. @GetMapping("/order/userPage")
  5. @ResponseBody
  6. public R<Page> userPage(@RequestParam"page")Integer page,@RequestParam"pageSize")Integer pageSize){}

2.将参数拼接在url中,后台通过占位符接收参数   /{id}

  1. async initData(){
  2. const res = await addressFindOneApi(params.id)
  3. }
  4. ​​​​​​​function addressFindOneApi(id) {
  5. return $axios({
  6. 'url': `/addressBook/${id}`,
  7. 'method': 'get',
  8. })
  9. }

后端接收参数

  1. @GetMapping("/addressBook/{id}")
  2. @ResponseBody
  3. public R<AddressBook> backList(@PathVariable("id")Long id){}

3.通过post提交方式将form表单中的数据序列化后传递到后台。

  1. async initData(){
  2.     const res =await formAjax();
  3. }
  4. function formAjax() {
  5.        $.ajax({
  6.        url: "/login"
  7.        type: "post"
  8.        data: $("#form").serialize(),  // 对id为form的表单数据进行序列化并传递到后台

后端接收参数

  1. @RequestMapping("/login")
  2. @ResponseBody
  3. //form表单的数据与User实体类的数据相对应
  4. public String login (User user) {}

4.通过post提交方式将form表单的类型是 json 

  1. async initData(){
  2.     const res =await formAjax();
  3. }
  4. function formAjax() {
  5.        $.ajax({
  6.        url: "/login"
  7.        type: "post"
  8. contentType: 'application/json',

后端接收参数

  1. @RequestMapping("/login")
  2. @ResponseBody
  3. //form表单的数据与User实体类的数据相对应
  4. public String login ( @RequestBody User user) {}

5. 前台将普通数据转换为json

  1. async initData(){
  2. paging: {
  3. page: 1,
  4. pageSize: 5
  5. }
  6. const res = await orderPagingApi(this.paging)
  7. }
  8. function orderPagingApi(data) {
  9. return $axios({
  10. 'url': '/order/userPage',
  11. 'method': 'post',
  12. data: JSON.stringify(data),
  13. })

后台接收参数

  1. @GetMapping("/order/userPage")
  2. @ResponseBody
  3. public R<Page> userPage(@RequesBody Map<Integer,Integer> map){
  4. Integer page = map.get("page");
  5. Integer pageSize = map.get("pageSize");
  6. }
  7. 或 ==>>
  8. //假设PageInfo类中有属性与其相对应
  9. @GetMapping("/order/userPage")
  10. @ResponseBody
  11. public R<Page> userPage(@RequesBody PageInfo pageInfo){
  12. Integer page = pageInfo.getPage();
  13. Integer pageSize = pageInfo.getPageSize();
  14. }

6.接收参数出错案例

Cannot deserialize instance of `java.lang.String` out of START_OBJECT token

中的 user 被认为是一个Object对象,不能用String进行解析

  1. 修改前
  2. @PostMapping("/regiest")
  3. public R<String> createUser(@RequestBody Map<String,String> map) {
  4. return R.success("保存成功");
  5. }
  6. 修改后
  7. @PostMapping("/regiest")
  8. public R<String> createUser(@RequestBody Map<String,Object> map) {
  9. return R.success("保存成功");
  10. }

7. 使用vue时Error in render: "TypeError: getStatus is not a function"

在 new Vue({

  getStatus()  ; //方法出错

} )

我的原因是粗心少了一个         使得这个方法不准确

8.前端传参 {params: params} ,后端用 @RequestParams("id") 接参

  1. //前端发送数据
  2. this.$axios
  3. .delete("login/deleteUserInfo",
  4. { params: {
  5. userId: this.id
  6. }
  7. })
  8. .then(
  9. this.$message({
  10. type: "success",
  11. message: "删除用户信息成功",
  12. }))
  13. .catch(
  14. this.$message({
  15. type: "false",
  16. message: "删除用户信息失败",
  17. })
  18. )
  19. //后端接收数据
  20. @DeleteMapping("deleteUserInfo")
  21. public R deleteUserInfo(@RequestParam("userId") String userId){
  22. int result=userInfoService.deleteUserInfoById(userId);
  23. if(result>0){
  24. return R.ok();
  25. }
  26. return R.error();
  27. }

9.前端通过 {data : param} 传参,后端通过 @RequestBody  接参

  1. //前端
  2. deleteMessage() {
  3. axios.delete('login/deleteUserInfo',
  4. { data : {
  5. userId: this.id
  6. }}).then((response) => {
  7. });
  8. }
  9. //后端
  10. @DeleteMapping("deleteUserInfo")
  11. public R deleteUserInfo(@RequestBody String userId){
  12. int result=userInfoService.deleteUserInfoById(userId);
  13. if(result>0){
  14. return R.ok();
  15. }
  16. return R.error();
  17. }

10、el-select 数据回显问题

  1. <el-form-item label="角色名称:" label-width="100px">
  2. <el-select
  3. placeholder="请选择角色名称"
  4. v-model="form.roleId"
  5. :label-width="formLabelWidth"
  6. style="width: 200px"
  7. >
  8. <el-option
  9. v-for="item in roleInfo"
  10. :key="item.value"
  11. :label="item.roleName"
  12. :value="item.roleId"
  13. >
  14. </el-option>
  15. </el-select>
  16. </el-form-item>

:value='1'  v-model="1"(数值 1)则匹配(number=number string=string类型要一致),显示label 否则显示value

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发