简体   繁体   English

request.setAttribute()和model.addAttribute之间有什么区别?

[英]what differencies between request.setAttribute() and model.addAttribute?

What differencies between request.setAttribute() and model.addAttribute ? request.setAttribute()和model.addAttribute之间有什么区别? I am about servlets api and spring-mvc wrapper for this api 我是关于Servlet API和该API的Spring-MVC包装器

Model is an abstraction. 模型是一种抽象。 You could use Spring with servlets, portlets or other frontend technologies and Model attributes will always be available in your respective views. 您可以将Spring与servlet,portlet或其他前端技术一起使用,并且Model属性将始终在您各自的视图中可用。

HttpServletRequest on the other hand is an object specific for Servlets. 另一方面,HttpServletRequest是特定于Servlet的对象。 Spring will also make request attributes available in your views, so from a user perspective there is not much difference. Spring还将使请求属性在您的视图中可用,因此从用户角度看并没有太大区别。

Another aspect is that models are more lightweight and more convenient to work with. 另一方面是模型更轻巧,使用起来更方便。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM