【发布时间】:2018-11-18 11:00:37
【问题描述】:
我尝试解决编码问题。所以,我从“邮递员”发送,从网络浏览器请求到服务器,在那里我通过请求中的键搜索数据库中的数据。请求可以是这样的:
http://localhost:8080/books.getBooksByGenre/Документальное/0/10
(在浏览器中)。 服务器接收字符串,如
http://localhost:8080/books.getBooksByGenre/%D0%94%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D0%B0%D0%BB%D1%8C%D0%BD%D0%BE%D0%B5/0/10
然后,从 url 获取参数: 流派名称:'Документальное' 开始:0 数:10。 然后,这个数据发送到 dao:
override fun findGenreByName(genreName: String): DatabaseGenre {
return transaction(db) { getGenreByName(genreName) }
}
private fun getGenreByName(genreName: String): DatabaseGenre {
return try {
val foundGenre = GenreEntity.find { Genres.genre eq genreName }.single()
DatabaseGenre(foundGenre.id.value, foundGenre.genre, foundGenre.link)
} catch (e: Exception) {
throw NothingFoundInDatabaseException("no one genre found by '$genreName'")
} catch (e: NoSuchElementException) {
val m = "Duplicates of genre with name '$genreName'"
throw DuplicatedDataInDatabaseException(m)
}
}
在我看到的日志中,用于查找流派的 sql-query 是正确的,但我收到了一个异常:
java.util.NoSuchElementException: Collection is empty.
正如我所说,sql-query 是正确的:
SELECT genres.id, genres.genre, genres.link FROM genres WHERE genres.genre = 'Документальное'
流派表结构:
genres
id: int(10)
genre: varchar(100)
link: varchar(100
我尝试选择所有类型,并且该查询几乎正确执行。所以,我决定用英文单词检查这个查询,并且这个查询正确执行:
SELECT genres.id, genres.genre, genres.link FROM genres WHERE genres.genre = 'simpleGenre'
我对这个查询没有例外。
那么,我做错了什么以及如何解决排序规则问题?
更新: 正如我在 github (issue) 所说的,我已经在 mysql cli 中尝试过这个查询,我得到了正确的答案。
另外,我尝试解码 url 参数(使用 java URLDecoder 类)。它也没有帮助。
【问题讨论】:
-
嗯,是的。这称为 URL 编码。如果它没有自动解码,则需要手动进行。
-
@Zoe,感谢您的回答。但是,为什么我在日志中看到带有西里尔字母的 sql-query(以“正常”形式)?它没有编码符号,只是普通的西里尔字母。 p.s.我会尝试你的建议并在这里写结果
-
@Zoe,我已经尝试过你的建议。它没有帮助。我更新了我的问题描述,尝试解决这个问题并链接到 github 问题,我在 mysql cli 中写的一切都很好
-
你的 MySQL 连接 URL 中有
characterEncoding=utf8参数吗?喜欢jdbc:mysql://localhost:3306/db?characterEncoding=utf8。另一个有用的参数是useUnicode=true。 -
@madhead,fuu** ghm,它真的很管用。非常感谢你。花了一周的时间。不知道,如何标记为正确答案
标签: kotlin orm collate kotlin-exposed