Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

当设置接口 结构体 时间类型为 DateTime 时。接口返回(例如:2023-12-21T16:08:48Z),在前端做时间处理时异常 #482

tpc-ht started this conversation in Ideas
Discussion options

image
image
服务端调用 .format 解析是对的。但查询sql与响应的 结构体 都是一个所以并未做二次格式化处理,想直接前端处理。

请问有什么办法可以解决了

You must be logged in to vote

Replies: 1 comment · 1 reply

Comment options

image image 服务端调用 .format 解析是对的。但查询sql与响应的 结构体 都是一个所以并未做二次格式化处理,想直接前端处理。

请问有什么办法可以解决了

可选方案

  • 前端修改一下代码支持RFC3339时间编码即“2023-12-12T:00:00:00Z”/“2023-12-12T:00:00:00+08:00”
  • 服务端增加一层VO层(MVC设计模式的View层),例如
UserVO{  pub time:String  }

impl From<User> for UserVO{
   .....
}

//业务代码
#[tokio::main]
async fn main(){
  let user:User = User::select_by_column(rb,"id",1).await.unwrap();
  let user_vo = UserVO::from(user);
 // 返回 user_vo  给前端
}
You must be logged in to vote
1 reply
@tpc-ht
Comment options

谢谢大佬,这个写法很好用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
💡
Ideas
Labels
done done
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.