通过Syncfusion Datamanager为多部分/混合帖子构建弹簧控制器



您好,我目前正在尝试构建一个与Syncfusion的Datamanager匹配的spring启动后端(据我所知,他们的后端构建文档纯粹是针对.NET的。 我已经设法让 GET 功能正常工作,所以我的数据类型映射是正确的,但发布会导致一些问题。 具体来说,DataManager 似乎发布了一个多部分/混合,其中包括我尝试保留的 JSON 对象以及某种批处理文件(我不关心(。 由于我无法修改数据管理器,我需要在 spring 中想办法纯粹提取 JSON。 我确定这真的很简单,但我对此相当陌生,找不到任何其他以前问过的问题来匹配我目前的情况。 以下是 Chrome 开发者工具中列出的请求详细信息的副本。

常规

请求网址: http://localhost:8082/schedule/$batch

请求方法:开机自检

状态代码:415

远程地址: [::1]:8082

推荐人政策:降级时禁止推荐人

响应标头

访问控制允许标头:授权、内容类型

访问控制-允许-方法:发布、放置、获取、选项、删除

访问控制允许来源: *

访问控制-最大年龄:3600

内容类型:应用程序/JSON

日期:2019 年 11 月 22 日星期五 14:38:39 GMT

传输编码:分块

变化:产地

变化:访问控制请求方法

变化:访问控制请求标头

请求标头

接受: application/json,

text/javascript,/; q=0.01, application/json

接受编码:gzip,deflate,br

接受语言:en-US,en;q=0.9

连接:保持活动状态

内容长度:358

内容类型:多部分/混合;边界=batch_dddabc0b-930c-47fc-b7e5-934999f0adc9

主机:本地主机:8082

产地:http://localhost:4200

推荐人: http://localhost:4200/main/schedule

秒取模式:秒

秒取站点:同一站点

用户代理:Mozilla/5.0(视窗NT 10.0;赢64;x64( AppleWebKit/537.36 (KHTML, like Gecko( Chrome/78.0.3904.108 Safari/537.36

请求有效负载

--batch_dddabc0b-930C-47FC-B7E5-934999f0ADC9

内容类型:application/http; msgtype=request

POST/api/null HTTP/1.1

内容类型:application/json;charset=utf-8

主机:本地主机:4200

{"主题":"m","Id":4,"开始时间":"2019-11-21T06:30:00.000Z",">

结束时间":"2019-11-21T07:00:00.000Z","IsAllDay":false}

--batch_dddabc0b-930C-47FC-B7E5-934999f0ADC9--***

这是我目前的控制器的副本。 (基本上是为了接受常规应用程序/json POSTS而构建的(

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.quietmodebackend.models.Appointment;
import com.quietmodebackend.repos.ScheduleRepository;
@CrossOrigin
@RestController
@RequestMapping("/schedule")
public class ScheduleController {
    @Autowired
    ScheduleRepository myRepo;
    @GetMapping
    public List<Appointment> getAppointments(HttpServletResponse response){
        response.setStatus(200);
        return myRepo.findAll();
    }
    @PostMapping("/$batch")
    public Appointment postAppointments(HttpServletResponse response, @RequestBody Appointment appointment){
        return myRepo.save(appointment);
    }

}

任何帮助将不胜感激。

Dear Customer,
Syncfusion Greetings
Scheduler CRUD actions support is not provided for WebApiAdaptor which could be the cause and for the same we already logged the below feature request.
https://www.syncfusion.com/feedback/2373/batch-handler-support-for-asp-net-core-while-using-webapi-adaptor
Kindly use UrlAdaptor like below sample.
Sample: https://stackblitz.com/edit/angular-ysiqa8-9s3lef?file=app.component.ts
Service: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-schedule-crud-1800404263 
 private dataManger: DataManager = new DataManager({
    url: "http://localhost:25255/api/Batch", 
    crossDomain: true, 
    adaptor: new UrlAdaptor 
  });
Note: Keep the Service project in runnable state.
Regards,
M.Vinitha devi

最新更新