Article From:

I. Spring Interview Questions

1、Spring What role does SSM play?

  • Spring:lightweight framework

  • Role: Bean factory, which manages the life cycle and framework integration of beans.

  • The two core:
    ①. IOC/DI(Control inversion/dependency injection: Dao dependency is injected into service layer, service layer is inverted to action layer, and Spring top container is BeanFactory.
    ②. AOP:AoP


  • Programming transaction management: Programming transaction management, great flexibility, difficult to maintain.

  • Declarative transaction management: Business code and transaction management can be separated, and transactions can be managed with annotations and XML configuration.

3、IOC Role in the project?

  • Role: Ioc solves the dependency problem between objects, associates all bean dependencies with configuration files or annotations, and reduces coupling.

4、SpringWhat is in the configuration file?

  • Open Transaction Annotation Driver

  • Transaction manager

  • Turn on the annotation function and configure the scanning package

  • Configuration database

  • Configure SQL Session Factory, Aliases, Mapping Files

  • You don’t need to write implementation classes for the Dao layer

5、SpringAnnotations below?

  • Registration: @Controller@Service@Component

  • Injection: @Autowired@Resource

  • Request address: @RequestMapping

  • Returns a specific data type instead of a jump: @ResponseBody

6、Spring DI Three ways?

  • Constructor injection: initialization by constructor method


<constructor-arg index="0" type="java.lang.String" value="BMW "& gt; & lt; / constructor - Arg & gt;


  • setterMethod injection: initialization by setter method


<property name="id" value="1111"></property>


  • Interface injection

7、SpringWhat are the main modes used?

  • Factory Patterns: Creation Approach for Each Bean

  • Singleton pattern: The default scope for each bean is singleton

  • Agent mode: about the implementation of Aop through agent mode

8、IOC,AOPThe realization principle?

  • IOC:Generating object injection through reflection mechanism

  • AOP:Dynamic proxy



2. Spring Mvc Interview Questions

1、SpringMvc Is the controller a singleton mode? If so, what’s the problem and how to solve it?

  • Problem: Singleton mode, thread security issues in multithreaded access

  • Solution: Don’t use synchronization. You can’t write segments in the controller.

2、SpringMvc Annotation of Controller?

  • @Controller:This annotation indicates that this class acts as a controller.

3、@RequestMapping The role of annotations in classes?

  • Role: Used to map a URL to a class or a specific processing method

4、Front desk parameters, these parameters are an object, quickly get the object?

  • Method: Declare the object directly in the method, and Spring Mvc automatically assigns attributes to the object.

5、SpringMvcThe return value of the middle function?

String,ModelAndView,List,Set etc.
General String, Ajax request, returns a List collection

6、SpringMvcForwarding and redirection in?

  • Forwarding: return: “hello”

  • Redirect: return: “redirect: hello. jsp”

7、SpringMvcMutual calls between Ajax and Ajax?

Through the JackSon framework, the objects in Java are directly converted into JSON objects that can be recognized by js. The specific steps are as follows:

  1. Join JackSon.jar

  2. Configure JSON mapping in configuration files

  3. In accepting Ajax methods, you directly return Object, list, etc. with the annotation @ResponseBody before the method

8、SpringMvcWork flow chart?


9、Struts2 What’s the difference between Spring Mvc and Spring Mvc?

  1. Different entries:

  • Struts2:filterFilter

  • SpringMvc:A Servlet is the Front-end Controller

  1. Different ways of development:

  • Struts2:Based on class development, passing parameters through class attributes can only be set to multiple instances.

  • SpringMvc:Based on method development (a URL corresponds to a method), the request parameters are passed to the method parameters, which can be singletons or multiple (recommended singletons)

  1. Requests are made in different ways:

  • Struts2:Data requested and responded by the value stack village, accessed through OGNL

  • SpringMvc:The request request request content is parsed by parameter parser, the method parameters are assigned, the data and views are encapsulated into ModelAndView objects, and finally the model data in ModelAndView is transmitted to the page through the request domain. The JSP view parserJSTL is used by default.



III. Mybatis Interview Questions

1、IbatisAnd Mybatis?

  • Ibatis:2010In 2001, apache’s Ibatis framework stopped updating and was handed over to the Google team, renamed MyBatis. Ibatis has not been updated since 2010 and has become an orphan framework. An unmaintained framework is destined to be filmed by mybatisOn the beach.

  • Mybatis:IbatisUpgrade version.

2、What is Mybatis’s interface binding and what are the benefits?

MybatisIt realizes the binding of DAO interface and XML Mapping file, and automatically generates the concrete implementation of interface for us, which makes it more convenient and convenient to use.

3、What cases are annotated and what cases are bound with xml?

  • Annotation usage: When Sql statements are simple

  • xmlBinding usage: XML binding (@RequestMap is used to bind XML files)

4、MybatisWhat is the name of the core processing class?


5、Query table name and return entity bean object are inconsistent, how to deal with it?

Mapping key-value pairs is enough

<result column="title" property="title" javaType="java.lang.String"/>


  • column:Column names of tables in the database

  • property:Property names in entity beans

6、MybatisThe benefits?

  • Separate Sql statements from Java.

  • It encapsulates the invocation of the underlying JDBC and API, and can automatically convert the result set into JavaBean objects, which simplifies the repetitive work of Java database programming.

  • Write Sql statements yourself, more flexible.

  • Entry does not need to be encapsulated with objects (or maps), using the @Param annotation

7、MybatisConfigure one to many?

<collection property="topicComment" column="id" ofType="com.tmf.bbs.pojo.Comment" select="selectComment" />


  • property:Attribute name

  • column:Common column

  • ofType:Types of elements in a collection

  • select:Queries to connect

8、MybatisConfigure one to one?

<association property="topicType" select="selectType" column="topics_type_id" javaType="com.tmf.bbs.pojo.Type"/>


  • property:Attribute name

  • select:Queries to connect

  • column:Common column

  • javaType:Types of elements in a collection

9 、${} What’s the difference?

  • ${}:Simple string substitution, which replaces ${} directly with the value of the variable without any conversion, is to compile the SQL statement after taking the value.

  • #{}:Pre-compiler processing, replacing #{} in sql? Complete the pre-compiled statements, effectively prevent Sql statement injection, this kind of value is compiled SQL statement and then take the value.
    Summary: Columns are generally replaced by #{}

10、Get the last autogenerated primary key value?

select last _insert_id()

11、MybatisHow to Page, Paging Principle?

  • RowBoundsObject paging

  • Write directly in Sql with physical Pagination

12、MybatisWorking principle?


    • SqlSessionFactory is constructed from mybatis-config.xml configuration file by SqlSessionFactory Builder.

    • SqlSessionFactoryOpen a SqlSession, get the Mapper object through the SqlSession instance, and run the Sql statement of the Mapper mapping.

    • Complete the CRUD operation and transaction submission of the database, and close SqlSession.


Link of this Article: SSM interview questions

Leave a Reply

Your email address will not be published. Required fields are marked *