What are template classes in Spring Java? Why are they called templates? For example jdbc-template, jms-template etc

后端 未结 3 899
后悔当初
后悔当初 2021-02-07 06:18

I\'m new to Java. I\'ve only been programming it for about a year. What does Spring mean by the use of templates? In Spring, there is jdbc-templates, jms-templates etc.. What ar

3条回答
  •  甜味超标
    2021-02-07 06:32

    These kind of classes are used to simplify the functionality, letting low level issues asside of, for example, connecting to the database (all the dirty work is done by the jdbcTemplate class).

    The JdbcTemplate simplifies the use of JDBC and helps to avoid common errors. It executes core JDBC workflow, leaving application code to provide SQL and extract results. This class executes SQL queries or updates, initiating iteration over ResultSets and catching JDBC exceptions and translating them to the generic, more informative exception hierarchy.

    The only thing you need to actually implement are the CallBack methods. Implementing only callback methods let your code clean. Your only concern is to execute your business logic.

提交回复
热议问题