当前位置: 首页 > news >正文

手机上传视频网站开发网站建设技术服务方案

手机上传视频网站开发,网站建设技术服务方案,成品直播app源码,多商户商城源码下载目录 1、Bean对象常用注解介绍 2、注解示例说明 1、Bean对象常用注解介绍 Component 通用类组件注解,该类被注解,IOC容器启动时实例化此类对象Controller 注解控制器类Service 注解业务逻辑类Respository 注解和数据库操作的类,如DAO类Reso…

目录

1、Bean对象常用注解介绍

2、注解示例说明


1、Bean对象常用注解介绍

  1. @Component 通用类组件注解,该类被注解,IOC容器启动时实例化此类对象
  2. @Controller 注解控制器类
  3. @Service 注解业务逻辑类
  4. @Respository 注解和数据库操作的类,如DAO类
  5. @Resource 装配注解,优先按名称装配,如果名称匹配不上,则按照类型匹配
  6. @Autowired 装配注解,按类型装配(Spring 内置)
  7. @Inject 装配注解,按类型装配(JSR-330标准)
  8. @PostConstruct 方法注解,功能参考xml文件中的init-method,在实例化对象后自动执行
  9. @Scope Bean属性注解,功能参考xml文件中的Scope属性,非WEB环境有多例和单例两种,注解不写value或者不写此注解的情况下,默认是单例
  10. @Value 属性注解,为Bean对象注入静态数据,通常属性注入的值来自某个配置文件

2、注解示例说明

IOC容器注解方式配置Bean需要如下步骤:

1、applicationContext.xml加入扫描的包,此包项下的类被IOC容器扫描,如有注解,则实例化对象

    <!-- 扫描注解包--><context:component-scan base-package="com.text"/><!-- 加载配置文件 --><context:property-placeholder location="classpath:config.properties"/>

        配置文件config.properties(示例jdbc连接)                

jdbc.url=jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxx

 2、配置Bean注解

package com.text.dao.impl;
import com.text.dao.StudentDao;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;
@Repository
@Scope("prototype") //多例,只是程序模拟,实际项目上大部分是单例
public class StudentDaoImpl implements StudentDao {@Value("${jdbc.url}")private String url;public String getUrl() {return url;}public void setUrl(String url) {this.url = url;}
}
package com.text.service.impl;
import com.text.dao.StudentDao;
import com.text.service.StudentService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class StudentServiceImpl implements StudentService {/*** @Resource 注解后,先从容器中找bean名称=studentDao的对象,没找到(系统中实例对象名称是studentDaoImpl)* 再通过类型StudentDao寻找,找到studentDaoImpl,注入到studentServiceImpl对象中* 由于studentDao是私有属性,IOC容器会通过反射技术将studentDao改为puclic属性(修改modifier值),* 然后赋值,赋值后再次将studentDao设置私有属性;此种方式和xml中的property的方式不同,property的方式是通过* 反射调用SetStudentDao方法实现注入*/@Resourceprivate StudentDao studentDao;public StudentDao getStudentDao() {return studentDao;}public void setStudentDao(StudentDao studentDao) {this.studentDao = studentDao;}
}

测试类:

package com.text.entity;import com.text.dao.StudentDao;
import com.text.dao.impl.StudentDaoImpl;
import com.text.service.impl.StudentServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test {public static void main(String[] args) {String configLocation = "classpath:applicationContext.xml";ApplicationContext context = new ClassPathXmlApplicationContext(configLocation);System.out.println("==========IOC容器完成初始化==========");String[] beanDefinitionNames = context.getBeanDefinitionNames();for(String beanDefinitionName:beanDefinitionNames) {System.out.println(beanDefinitionName);//studentDaoImpl  studentServiceImpl}StudentDao studentDao1 = context.getBean("studentDaoImpl", StudentDao.class);StudentServiceImpl studentService = context.getBean("studentServiceImpl", StudentServiceImpl.class);StudentDao studentDao2 = studentService.getStudentDao();System.out.println(studentDao1 == studentDao2);//false,studentDaoImpl scope=多例StudentDaoImpl studentDao3 = (StudentDaoImpl)studentService.getStudentDao();System.out.println(studentDao3.getUrl());//jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxx}
}

 特别说明:

@Resource 注解StudentServiceImpl 后,先从容器中找bean名称=studentDao的对象,没找到(系统中实例对象名称是studentDaoImpl)再通过类型StudentDao寻找,找到studentDaoImpl,注入studentServiceImpl对象的studentDao属性中,由于studentDao是私有属性,IOC容器会通过反射技术将studentDao改为puclic属性(修改modifier值),然后赋值,赋值后再次studentDao设置私有属性;此种方式和xml中的property的方式不同,property的方式是通过反射调用SetStudentDao方法

http://www.yayakq.cn/news/620787/

相关文章:

  • 长春企业自助建站系统hao123网址之家官网
  • dz网站建设视频教程网线制作注意事项
  • 网站流量2021给个最新网站
  • 福田区做网站公司深圳电器公司
  • 仿站多少钱一套短视频代运营合作方案
  • 上海浦东做网站的公司wordpress建企业展示
  • 网络营销包括哪些基本内容网址seo分析
  • 网站文章怎么做才能被快速收录中国住房和城乡建设部网站官网
  • 网站轮播广告动画怎么做微信小商店怎么推广
  • 福建住房和建设网站密码忘记英国做电商网站
  • 2018年网站建设发言wordpress 还原备份
  • 自适应营销网站江西网站开发联系方式
  • 网站手机端做app开发工具建筑人才网站
  • 企业网站管理系统免费网页制作代码步骤
  • 如何做网站迁移营销活动方案模板范文
  • 网站服务器租用怎样收费网站 开发 周期
  • 网站建设分哪些类别济南企业营销型网站建设
  • 深圳龙华做网站公司外贸招聘网最新招聘
  • 广州市车管所网站建设WordPress获取文章封页
  • 沈阳网站seo排名网页设计素材图片黑白
  • 昆明pc网站建设伪装的福祉 wordpress
  • 网站关键字 怎么设置化妆品公司网站设计
  • 丽江市网站建设军事新闻最新消息今天
  • 网站建设服务器维护内容ip38域名信息查询网站
  • 模版型网站如何建设自己网站首页
  • 用自己电脑做网站服务器-phpstudy+花生壳seo网络营销技术
  • 昆明网站的建设可以举报一个做网络网站发大财吗
  • 呼伦贝尔旅游网站建设app网站开发成本
  • 做弹幕网站有哪些wordpress表白系统
  • 网站建设公司厦门有哪些网站点击量查询