面试第一弹-续

面试第一弹-续


1. 数据库表连接
  • 内连接

    select a.*, b.* from tablea a  
    join tableb b  
    on a.id = b.id
    ------------------------------
    取公有部分(交集),可得到所有属性
  • 外连接

    • left join == left outer join

      select a.*, b.* from tablea a  
      left join tableb b  
      on a.id = b.id 
      ------------------------------
      a表中所有记录,加上b表属性
    • right join == right outer join

      select a.id aid,a.age,b.id bid,b.name from tablea a  
      right join tableb b  
      on a.id = b.id  
      ------------------------------
      b表中所有记录,加上a表属性
    • full join (mysql中不支持,可用 left join union right join代替)

      select a.id aid,a.age,b.id bid,b.name from tablea a  
      left join tableb b  
      on a.id = b.id  
      union  
      select a.id aid,a.age,b.id bid,b.name from tablea a  
      right join tableb b  
      on a.id = b.id
      -----------------------------------------------------
      并集
  • 交叉连接(cross join)

    select a.id aid,a.age,b.id bid,b.name from tablea a  
    cross join tableb b 
    ---------------------------------------------------
    笛卡尔积:a表中每条记录都与表b连接
    产生a*b条记录
    2. Springmvc的工作流程
  1. DispatcherServlet拦截用户的请求,调用HandlerMapping处理器映射器找到对应的Handler(Controller类),将Handler返回给DispatcherServlet。

  2. DispatcherServlet根据Handler调用合适的处理器适配器HandlerAdapter去调用Handler方法,得到ModeAndView对象返回给DispatcherServlet。

  3. DispatcherServlet根据ModeAndView调用合适的视图解析器ViewResolver 得到View,然后对View进行渲染,返回视图给用户。

3. spring Ioc容器和springmvc ioc容器的区别
web.xml 中提供ContextLoaderListener监听器,web容器启动时会触发容器初始化事件,Spring会初始化一个根上下文,即WebApplicationContext(具体实现类XmlWebApplicationContext),管理的bean在context-param标签中配置,一般管理service、DataSource等。
DispatcherServlet在初始化的时候会建立自己的IoC上下文(以spring ioc容器为父容器,mvc可以调用其中的bean,反之不行),用以持有Spring mvc相关的bean。如controller、ViewResolver、HandlerMapping等。

猜你喜欢

转载自www.cnblogs.com/luo-bo/p/11123503.html
今日推荐