MVC面试题:有了stuts的mvc为什么还要spring的mvc
今天一同学 去面试 关于mvc的面试题
面试官问道:有了stuts的mvc为什么还要spring的mvc ,你觉得spring有什么不爽的地方?
我同学一时哑了 想了半天不知道该怎么说 乱七八糟说了一通 面试官说 please get out !
大家有什么要说的没 69 楼 mysoko 2010-11-25 面试官傻x 70 楼 mopishv0 2010-11-25 因为可以使用SPRING的一站式解决方案
71 楼 stone0660 2010-11-25
最近用到了一个公司基于SpringMVC封装的框架,
最大的感受就是SpringMVC对于View的支持很广泛。
比如支持Velocity View, 基于Castor的XML View等等。
StrutsMVC(至少ver1.x)好像只能支持JSP。
关于SpringMVC,springsource上有如下说法:
http://forum.springsource.org/showthread.php?t=16553
1. Spring provides a very clean division between controllers, JavaBean models, and views.
2. Spring's MVC is very flexible. Unlike Struts, which forces your Action and Form objects into concrete inheritance (thus taking away your single shot at concrete inheritance in Java), Spring MVC is entirely based on interfaces. Furthermore, just about every part of the Spring MVC framework is configurable via plugging in your own interface. Of course we also provide convenience classes as an implementation option.
3. Spring, like WebWork, provides interceptors as well as controllers, making it easy to factor out behavior common to the handling of many requests.
4. Spring MVC is truly view-agnostic. You don't get pushed to use JSP if you don't want to; you can use Velocity, XLST or other view technologies. If you want to use a custom view mechanism - for example, your own templating language - you can easily implement the Spring View interface to integrate it.
5. Spring Controllers are configured via IoC like any other objects. This makes them easy to test, and beautifully integrated with other objects managed by Spring.
6. Spring MVC web tiers are typically easier to test than Struts web tiers, due to the avoidance of forced concrete inheritance and explicit dependence of controllers on the dispatcher servlet.
7. The web tier becomes a thin layer on top of a business object layer. This encourages good practice. Struts and other dedicated web frameworks leave you on your own in implementing your business objects; Spring provides an integrated framework for all tiers of your application. 72 楼 wait10000y 2010-12-13 人家是不想重新发明轮子了~!不是谁该不该出现的问题~! 73 楼 ro87630872 2010-12-19 我觉得 你的面试官问你这个问题 大约想了解 你对Spring 和Struts 的理解 主要针对模式方面, 如果是我 我会跟他说 Struts 的精髓是MVC 而Spring 主要是用它的AOC 和IOC/DI 至于Spring MVC 真的很少用! 然后重点再说说Struts 的MVC 和Spring 的模式 就OK了 74 楼 cesymm 2011-03-23 直接对面试官说,有你妈就行,还要你爸干嘛 75 楼 橄榄绿 2011-04-18 问这个问题的面试官也够态度的。不过这也从侧面反正出一个人的能力。。。 76 楼 hz020815 2011-05-25 那些技术不咋地的人,为了充胖子,就爱这样。扯一些莫名其妙的问题,要么就扯一些让你云里雾里的概念。曾经遇到过session都不懂的,还做项目经理(技术类的) 77 楼 icezx 2011-05-27 你直接问面试官:你是sb吗 78 楼 瑾绣山河 2011-05-27 没用过struts,一直在用spring mvc rest和注解确实蛮好用的。还有这个面试官,面试就怕碰到这样的面试官。 79 楼 hehe456as 2011-05-29 面试官的问题确实比较没水平……spring很爽,最成功的JEE框架
看struts就不爽 80 楼 george_space 2011-05-30 liujun999999 写道人家应该是想问这2种MVC的区别以及优缺点吧?
肯定是问这个问题,楼上众人狂批面试官,不知道是不是经常要面试的缘故。 81 楼 kkvsyy 2011-06-02 有了男人 有了女人 perfect 82 楼 weng 2011-06-03 downpour 写道你可以反问它,你每天都要拉屎,为什么还要吃饭?
你这样反问他就可以了,SB的问题,这样的公司不去也罢 83 楼 ydwcn 2011-06-03 有了stuts的mvc为什么还要spring的mvc ,你觉得spring有什么不爽的地方?
这话不合适吧。MVC是J2EE里面的一个架构思想,只是struts spring 同对其做了实现。咋能说有这个不能有那个? 84 楼 yjc2020 2011-06-03 这问题问的真SB 85 楼 泉州俺最牛 2011-06-04 学习了。原来是这样 86 楼 wing929 2011-06-04 http://www.blogjava.net/bolo/archive/2011/06/01/351028.html 87 楼 supben 2011-06-13 fover1985 写道个人觉得两者之间的区别还是比较明显的,先说一下他们的共同点:
1.都是mvc框架;
2.感觉struts的action类似于spring的ioc,都是使用java反射机制来实现的依赖注入;
3.struts2的拦截器使用也类似于spring的aop,都是通过动态代理实现的;
他们的区别,在我看来有如下:
1.配置不一样(这点就不多说了)
2.spring的控制器对象的处理请求方法需要带有HttpServletRequest和HttpServletResponse参数,这样不便于调试;
3.参数的接收,在struts2中通过set方法就实现了,而spring则取药显式的去从request中获取,另外参数的传递也比较方便;
4.struts2处理请求的返回页比较方便,通过acction的返回的结果名称,定位返回的页面或者重定向到另一个action
5.struts2同时提供了对于请求变量的校验和类型的转换;
6.我觉得spring在mvc框架中相对于struts2的优势在于它的IOC,struts2只是注入action,而spring可以将更多的bean注入到这个action中;
综上所述,springmvc较struts2更轻量,但是没有struts2在mvc方面功能强大;
黑白全被颠倒了。不知所云 88 楼 Java_KAbanban 2011-06-14 我感觉spring mvc比Struts的mvc好用,开发快,使用也很方便。