September Tencent, Baidu, Ali SSM frame frequency of 29 questions surface Analytical

A, Spring face questions
1, Spring What role in ssm in?
  • Spring: lightweight frameworks
  • Role: Bean plant Bean used to manage the life cycle and integrated framework.
  • Two core: 1, IOC / DI (Inversion of Control / Dependency injection): The dao dependency injection into the service layer, service action to the inversion layer layer, Spring top container is BeanFactory. 2, AOP: Aspect Oriented Programming
2, Spring of affairs?
  • Programmatic transaction management: programmatic transaction management, great flexibility, difficult to maintain.
  • Declarative transaction management: service code and transaction management can be separated, with annotations and xml configured to manage transactions.
3, the role of IOC in the project?
Role: Ioc resolution of dependencies between objects, all the dependencies Bean through configuration files or annotations associate, reducing the degree of coupling.
4, Spring configuration file contents?
  • Open annotation-driven transactions
  • Transaction Manager
  • Open comments, and configure the scan package
  • Configuration database
  • SQL session factory configuration, alias, mapping file
  • Instead of writing class that implements layer Dao
5, notes in Spring?
  • Registration: @Controller @Service @Component
  • Injection: @Autowired @Resource
  • Request Address: @RequestMapping
  • Return specific data types and not Jump: @ResponseBody
6, Spring DI of three ways?
Constructor injection: initializing constructor
<constructor-arg index = "0" type = "java.lang.String" value = "宝马" ></constructor-arg>
Method setter injection: initializing method setter
<property name = "id" value = "1111" ></property>
Interface injection
7, Spring mainly used what model?
  • Factory mode: Each method created by Bean
  • Singleton pattern: The default for each Bean scopes are single cases
  • Proxy mode: Aop achieved through a proxy mode on the
8, IOC, AOP implementation principle?
  • IOC: generating a reflection by the object injection
  • AOP: Dynamic Proxy
Two, SpringMvc face questions
1, SpringMvc controller is not a singleton, and if so, what is the problem, how to solve?
  • Question: singleton, thread-safe in a multithreaded access problems
  • Solution: Do not use sync, you can not write field controller inside
2, notes SpringMvc the controller?
@Controller: This comment indicates that the class role-playing controller
3, @ RequestMapping comment on the role of class with?
Action: used to map a URL to a particular class or a method of treatment
4, the front desk multiple parameters, which is an object, the object quickly get?
Method: Direct declare this object in a method, SpringMvc will automatically assign attributes to this object inside
5, SpringMvc the return value of a function?
String,ModelAndView,List,Set 等
General String, Ajax request, returns a List collection
6, SpringMvc forwarding and redirection?
  • Forwarding: return: "hello"
  • Redirect: return: "redirect: hello.jsp"
7, call each other between SpringMvc and Ajax?
JackSon frame by which the object is directly converted into java json js identifiable objects, the following steps:
  • Join JackSon.jar
  • Json configuration mapping in the configuration file
  • Back Object, list the like directly inside the receiving method Ajax foregoing method requires annotate @ResponseBody
8, SpringMvc work flow chart?
9, Struts2 and SpringMvc difference?
Different entrance:
  • Struts2: filter filters
  • SpringMvc: a front controller Servlet i.e.
Development of different ways:
  • Struts2: development class, attribute parameters passed based on the class, only to cases of
  • SpringMvc: Based Method Development (a method corresponding to a url), request parameters passed to the method parameter, a single embodiment may also be cases of (singleton recommended)
Request different ways:
  • Struts2:值栈村塾请求和响应的数据,通过OGNL存取数据
  • SpringMvc:通过参数解析器将request请求内容解析,给方法形参赋值,将数据和视图封装成ModelAndView对象,最后又将ModelAndView中的模型数据通过request域传输到页面,jsp视图解析器默认使用的是jstl。
三、Mybatis面试题
1、Ibatis和Mybatis?
  • Ibatis:2010年,apache的Ibatis框架停止更新,并移交给了google团队,同时更名为MyBatis。从2010年后Ibatis在没更新过,彻底变成了一个孤儿框架。一个没人维护的框架注定被mybatis拍在沙滩上。
  • Mybatis:Ibatis的升级版本。
2、什么是Mybatis的接口绑定,有什么好处?
Mybatis实现了DAO接口与xml映射文件的绑定,自动为我们生成接口的具体实现,使用起来变得更加省事和方便。
3、什么情况用注解,什么情况用xml绑定?
  • 注解使用情况:Sql语句简单时
  • xml绑定使用情况:xml绑定 (@RequestMap用来绑定xml文件)
4、Mybatis在核心处理类叫什么?
SqlSession
5、查询表名和返回实体Bean对象不一致,如何处理?
映射键值对即可
<result column = "title" property = "title" javaType = "java.lang.String" />
  • column:数据库中表的列名
  • property:实体Bean中的属性名
6、Mybatis的好处?
  • 把Sql语句从Java中独立出来。
  • 封装了底层的JDBC,API的调用,并且能够将结果集自动转换成JavaBean对象,简化了Java数据库编程的重复工作。
  • 自己编写Sql语句,更加的灵活。
  • 入参无需用对象封装(或者map封装),使用@Param注解
7、Mybatis配置一对多?
<collection property = "topicComment" column = "id" ofType = "com.tmf.bbs.pojo.Comment" select = "selectComment" />
  • property:属性名
  • column:共同列
  • ofType:集合中元素的类型
  • select:要连接的查询
8、Mybatis配置一对一?
<association property = "topicType" select = "selectType" column = "topics_type_id" javaType = "com.tmf.bbs.pojo.Type" />
  • property:属性名
  • select:要连接的查询
  • column:共同列
  • javaType:集合中元素的类型
9 、${} 和 #{}的区别?
  • ${}:简单字符串替换,把${}直接替换成变量的值,不做任何转换,这种是取值以后再去编译SQL语句。
  • #{}:预编译处理,sql中的#{}替换成?,补全预编译语句,有效的防止Sql语句注入,这种取值是编译好SQL语句再取值。
总结:一般用#{}来进行列的代替
10、获取上一次自动生成的主键值?
select last _insert_id()
11、Mybatis如何分页,分页原理?
  • RowBounds对象分页
  • 在Sql内直接书写,带有物理分页
12、Mybatis工作原理?
原理:
  • 通过SqlSessionFactoryBuilder从mybatis-config.xml配置文件中构建出SqlSessionFactory。
  • SqlSessionFactory开启一个SqlSession,通过SqlSession实例获得Mapper对象并且运行Mapper映射的Sql语句。
  • 完成数据库的CRUD操作和事务提交,关闭SqlSession。
 
最后
欢迎大家一起交流,喜欢文章记得点个赞哟,感谢支持!

Guess you like

Origin www.cnblogs.com/zhuifeng523/p/11609609.html