这只是有关在Web服务器上执行CRUD操作的一般问题。每次用户(例如,用户)想要在某个组中发帖时,我们都应该通过执行以下操作来始终检查该组是否存在,然后再执行apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.utkarshdeepanjan.emotiondetector2"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.microsoft.projectoxford:emotion:1.0.355'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.microsoft.projectoxford:emotion:1.0.355'
}
操作:
INSERT
还是不是首选,因为这会导致性能问题?但这也更安全...
答案 0 :(得分:2)
我对您的设计感到困惑,因为用户可以指定一个不存在的组。这似乎是问题的根本原因。
为防止“发布到不存在的组”,您可以定义一个外键,从groupId
中的posts
到groups
表。瞧数据库确保它们存在。
但进一步。 。 。使用groupId
表示该组存在。因此,如果您的代码“在幕后”使用id,那么这根本不是问题。