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

后端 未结 3 905
后悔当初
后悔当初 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:33

    They are called template as use the Template method pattern.

    Basically the idea is define the operation needed to do something in an abstract class or super class then implement a class that use the operation previous defined.

    In the case of spring allow that operation that always need to be done for an specific purpose be done automatically, (open connection, obtain for pool, translation, execution, close connection), then user only need to call methods without worries about the previous tasks.

提交回复
热议问题