当我向 Web 服务发出 POST 请求时,会生成以下错误:

TinyTds::错误:无法将值插入“ bankCd”列,表'slotsmasterdata.master.bank';列不允许为空。

服务器控制台显示以下内容:

enter image description here

从上面您可以看到我的 Bank 对象的所有属性都存在值,但是当 'SELECT CAST(SCOPE IDENTITY() ...' 被执行。

这是我的应用程序代码:

    RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:basePathToWebService]];

    RKObjectMapping *bankMapping = [RKObjectMapping mappingForClass:[Banks class]];

    NSDictionary *attributeMappingDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                                @"BankID", @"bankID",
                                                @"BankCD", @"bankCD",
                                                @"BankName", @"bankName",
                                                @"InsertSourceKey", @"insertSourceKey",
                                                @"UpdateSourceKey", @"updateSourceKey",
                                                @"Active", @"active",
                                                nil];

    [bankMapping addAttributeMappingsFromDictionary:attributeMappingDictionary];

    RKObjectMapping *bankRequestMapping = [RKObjectMapping requestMapping];
    [bankRequestMapping addAttributeMappingsFromDictionary:attributeMappingDictionary];

    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:bankMapping method:RKRequestMethodAny pathPattern:@"/banks" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

    RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:bankRequestMapping objectClass:[Banks class] rootKeyPath:nil method:RKRequestMethodAny];

    [objectManager addResponseDescriptor:responseDescriptor];
    [objectManager addRequestDescriptor:requestDescriptor];

    [RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class] forMIMEType:@"text/plain"];

    //Post
    [objectManager postObject:bank path:@"/banks" parameters:nil success:nil failure:nil];

为什么尝试插入 NULL 值?我该如何解决?感谢您的帮助!

有帮助吗?

解决方案

bankRequestMapping 应声明为的逆映射 bankMapping. 。正如您目前所看到的,参数名称似乎是错误的。您应该使用 Charles 检查您实际发送的内容以及它是否符合您的预期。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top