Giter Club home page Giter Club logo

spring-boot-service-component's Introduction

Spring Boot(十二)— 服务组件

所谓的服务组件(Service Component)— 就是用于处理系统业务逻辑的类,如果按照系统分层设计理论来划分,服务组件是位于业务层当中的类。在Spring Boot中,服务组件是一个被**@Service**注解进行注释的类,这些类用于编写系统的业务代码。在本章节中,将讲解如何创建并使用服务组件。

在开始正文之前,先来看两段示例代码。使用服务组件之前,我们需要定义服务组件接口类,用于索引服务组件提供的服务,代码如下所示:

public interface UserService{
    // TODO ...
}

然后,需要使用**@Service**注解对服务组件接口实现类进行注释,演示代码如下:

@Service(value="userService")
public class UserServiceImpl implements UserService{
    //TODO ...
}

最后,使用**@Autowired**注解来自动引用服务组件,代码如下:

@Controller
public class DemoController{
    @Autowired
    UserService userService;
    //TODO ...
}

在本次讲解中,我们依然以对用户的增、删、改、查为案例,将控制器中的业务方法迁移到服务组件中。


如需查看本教程完整的内容,请访问RT社圈或者点击下面的链接进行查看: Spring Boot(十二)— 服务组件 | ramostear · 罗摩尔

spring-boot-service-component's People

Contributors

ramostear avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.