zoukankan      html  css  js  c++  java
  • springMvc基本注解:@Component、@Repository(持久层) 、@Service(业务逻辑) 、@Controller(控制层)

    1、@Controller(控制层) :就是action层

    2、@Service(业务逻辑) :业务逻辑层,负责处理各种控制层的操作

    3、@Repository(持久层) :称为“持久化”层,负责对数据库的访问,各种CRUD操作!

    @Component:只需要在对应的类上加上一个@Component注解,就将该类定义为一个Bean了

    说明:四个注解效果一样,spring会自动当当作需要注入的Bean加载上下文中。

    案例:

    1. 控制层

      @Controller // 注释为controller

      @RequestMapping("/login")

      public class LoginAction {

      @Autowired

      @Qualifier("userService") //注释指定注入 Bean

      private IUserService userService;

      。。。。。。 其他略 。。。。。。

      }

    2. 业务逻辑层

      @Service("userService")

      public class UserServiceImpl implements IUserService {

      @Autowired

      @Qualifier("userDao")

      private IUserDao userDao;

      }

    3. 持久层

      @Repository("userDao")

      public class UserDaoImpl implements IUserDao {

      private static Logger logger = LoggerFactory.getLogger(UserDaoImpl.class);

      private DataSource dataSource;

      private JdbcTemplate template;

      @Autowired

      public UserDaoImpl(DataSource dataSource){

      this.dataSource= dataSource;

      template = new JdbcTemplate(this.dataSource);

      }

  • 相关阅读:
    值币转换编程总结
    打印沙漏编程总结
    Leetcode每日一题 面试题 17.21. 直方图的水量
    VS2017-OPENGL配置glfw+glad
    OpenGL(二) 绘制一个三角形
    OpenGL(一) 渲染循环创建窗口
    Leetcode每日一题 1006.笨阶乘
    Leetcode每日一题 90.子集 II
    Leetcode每日一题 190.颠倒二进制位
    Leetcode 第243场周赛 创新奇智&力扣
  • 原文地址:https://www.cnblogs.com/xxt19970908/p/5289667.html
Copyright © 2011-2022 走看看