当我有这样的API定义时:
(POST* "/register" []
:body-params [username :- String,
password :- String,
name :- String]
(ok)))
什么是使名称可选的合适方式?是吗:
(POST* "/register" []
:body-params [username :- String,
password :- String,
{name :- String nil}]
(ok)))
答案 0 :(得分:8)
如你所知它使用letk
管道符号并且我记得语法是正确的但是默认值应该与预期类型一致所以我认为它应该是""
而不是nil
与(string? nil)
= false
相比(POST* "/register" []
:body-params [username :- String,
password :- String,
{name :- String ""}]
(ok)))
extension String {
func stringByURLEncoding() -> String? {
let characters = NSCharacterSet.URLQueryAllowedCharacterSet().mutableCopy() as! NSMutableCharacterSet
characters.removeCharactersInString("&")
guard let encodedString = self.stringByAddingPercentEncodingWithAllowedCharacters(characters) else {
return nil
}
return encodedString
}
}
string query = string.Format("SELECT * from {0}", sym);
cmd.CommandText = query;
MySqlDataReader myresults = cmd.ExecuteReader();