Skip to content

Commit 94a98e1

Browse files
committed
1、修复multipart/form-data生成问题
1 parent d71f57e commit 94a98e1

7 files changed

Lines changed: 17 additions & 16 deletions

File tree

Annotation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747

4848
| 参数 | 类型 | 描述 | 必须 | 默认值 |
4949
| :------: | -------- | :---------------------------------------------: | :--: | :----: |
50-
| bodyType | BodyType | 类型:支持TEXT、JSON、FORM_DATA、FormUrlEncoded || JSON |
50+
| bodyType | BodyType | 类型:支持TEXT、JSON、FormData、FormUrlEncoded || JSON |
5151

5252
##### 7、@Query
53-
###### 描述:生成formData请求时使用。Body类型为FORM_DATA时,必须添加该注解修饰参数
53+
###### 描述:生成formData请求时使用。Body类型为FormData时,必须添加该注解修饰参数
5454

5555
| 参数 | 类型 | 描述 | 必须 | 默认值 |
5656
| :---: | ------ | :--: | :--: | :----: |

annotations/src/main/java/com/hearthappy/annotations/Body.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package com.hearthappy.annotations
55
annotation class Body(val bodyType: BodyType = BodyType.JSON)
66

77
enum class BodyType {
8-
NONE, TEXT, JSON, HTML, XML, FORM_DATA,FormUrlEncoded
8+
NONE, TEXT, JSON, HTML, XML, FormData,FormUrlEncoded
99
}
1010

1111

app/src/main/java/com/hearthappy/viewmodelautomation/MyApplication.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.hearthappy.annotations.ServiceConfig
88
@ServiceConfig(baseURL = "https://api.apiopen.top/api")
99
//定义一个文件上传下载的服务地址
1010
@ServiceConfig(baseURL = "http://192.168.51.62:9998", key = "fileOperate")
11+
@ServiceConfig(baseURL = "http://192.168.31.206:8888", key = "Apifox")
1112
class MyApplication: Application() {
1213

1314
override fun onCreate() {

ktorexpand/src/main/java/com/hearthappy/ktorexpand/code/network/KtorTest.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ internal suspend fun multiFileUpload(partData: List<PartData>, listener: (suspen
9898

9999

100100
fun main() = runBlocking {
101-
val file = File("/Library/MyComputer/Software/Android/Git/ViewModelAutomation/test.jpeg")
101+
// val file = File("/Library/MyComputer/Software/Android/Git/ViewModelAutomation/test.jpeg")
102102

103-
println("exist:${file.exists()},${file.name}")
103+
// println("exist:${file.exists()},${file.name}")
104104

105105
//fileDownload(outputStream)
106106

@@ -127,7 +127,9 @@ fun main() = runBlocking {
127127
})
128128
println("http:${sendKtorUpload.bodyAsText()}")
129129
}*/
130-
val part1 = MultipartBody.Part {
130+
131+
//上传
132+
/*val part1 = MultipartBody.Part {
131133
part("file", file = file, contentDisposition = "filename=\"uploadFileName.png\"", contentType = ContentType.Image.PNG)
132134
}.formData {
133135
append("key2", "bbbbb")
@@ -141,5 +143,5 @@ fun main() = runBlocking {
141143
println("current:$a,total:$b")
142144
}
143145
144-
println("end...:")
145-
}
146+
println("end...:")*/
147+
}

processor/src/main/java/com/hearthappy/processor/AnnotationHandler.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ internal fun ViewModelProcessor.getRequestDataMap(roundEnv: RoundEnvironment, cr
8080

8181
val requestData = RequestData(requestClass, httpType, requestUrl, findBaseConfig, headers, fixedHeaders, methodParameters, requestParameters, requestBodyData, order, streamingParameters, multiPartParameters)
8282
this[requestClass]=requestData
83-
//sendNoteMsg("【RequestData】:$requestData")
83+
sendNoteMsg("【RequestData】:$requestData")
8484
}
8585
}
8686
}
@@ -111,10 +111,10 @@ private fun ViewModelProcessor.getMethodParameters(requestElement: Element, body
111111
BodyType.JSON, BodyType.FormUrlEncoded -> parameters.addAll(getMethodParameterByBodyKind(bodyElements, requestElement))
112112
BodyType.HTML -> {
113113
}
114-
BodyType.XML -> {
114+
BodyType.XML -> {
115115
}
116-
BodyType.FORM_DATA -> parameters.addAll(getMethodParameterByBodyKind(bodyElements, requestElement))
117-
else -> {
116+
BodyType.FormData -> parameters.addAll(getMethodParameterByBodyKind(bodyElements, requestElement))
117+
else -> {
118118
}
119119
}
120120
order?.let { parameters.add(ParameterData(it, "Int")) }
@@ -342,7 +342,7 @@ private fun getCurrentBodyQueryMap(currentBodyElement: Element, queryElements: M
342342
*/
343343
private fun ViewModelProcessor.createRequestBodyData(bodyType: BodyType, currentBodyElement: Element, queryElements: MutableSet<out Element>): RequestBodyData {
344344
val currentBodyParameterName = getCurrentBodyParameterName(currentBodyElement)
345-
return if (bodyType == BodyType.FormUrlEncoded || bodyType == BodyType.FORM_DATA) { //创建XWF数据类型所需的参数@Query列表
345+
return if (bodyType == BodyType.FormUrlEncoded || bodyType == BodyType.FormData) { //创建XWF数据类型所需的参数@Query列表
346346
val currentBodyQueryMap = getCurrentBodyQueryMap(currentBodyElement, queryElements)
347347
if (currentBodyQueryMap.isEmpty()) sendErrorMsg("The request class is ${currentBodyElement.asType()}, the specified BodyType is FormUrlEncoded, but the Query annotation is not declared, resulting in an error")
348348
RequestBodyData(bodyType, xwfParameters = currentBodyParameterName?.run { Pair(this, currentBodyQueryMap) })

processor/src/main/java/com/hearthappy/processor/GenerateViewModelFile.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.hearthappy.annotations.AndroidViewModel
44
import com.hearthappy.annotations.BindLiveData
55
import com.hearthappy.annotations.BindStateFlow
66
import com.hearthappy.processor.common.*
7-
import com.hearthappy.processor.model.RequestData
87
import com.hearthappy.processor.model.ServiceConfigData
98
import com.squareup.kotlinpoet.FileSpec
109
import com.squareup.kotlinpoet.KModifier
@@ -13,7 +12,6 @@ import com.squareup.kotlinpoet.TypeSpec
1312
import java.io.File
1413
import javax.annotation.processing.RoundEnvironment
1514
import javax.lang.model.element.Element
16-
import kotlin.system.measureTimeMillis
1715

1816
internal fun ViewModelProcessor.generateAndroidViewModelFile(roundEnv: RoundEnvironment, androidViewModelElements: MutableSet<out Element>, generatedSource: String, serviceConfigList: List<ServiceConfigData>): Boolean {
1917
if (androidViewModelElements.isEmpty()) {

processor/src/main/java/com/hearthappy/processor/ViewModelProcessor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import kotlin.system.measureTimeMillis
1717
* @Author ChenRui
1818
* @Date 2021/12/27-16:46
1919
* @Email 1096885636@qq.com
20-
* ClassDescription :
20+
* ClassDescription : 注解处理类
2121
* kotlin poet:
2222
* liveData.parameterizedBy(responseBean):liveData:声明类型,responseBean:泛型类型
2323
* FunSpec.addTypeVariable(TypeVariableName("T")) : 函数泛型 :fun <T> add()

0 commit comments

Comments
 (0)