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

快速网站仿制做网站价格

快速网站仿制,做网站价格,网站空间的申请,wordpress用户注册协议前言:在上篇文章中,小编写了一个Spring的创建和使用的相关博客:Spring的创建和使用-CSDN博客,但是,操作/思路比较麻烦,那么本文主要带领大家走进:Spring更加简单的读取和存储对象! 本…

前言:在上篇文章中,小编写了一个Spring的创建和使用的相关博客:Spring的创建和使用-CSDN博客,但是,操作/思路比较麻烦,那么本文主要带领大家走进:Spring更加简单的读取和存储对象!

本文主要讲解用注解来实现Spring更加简单的读取和存储对象:五大类注解

  • @Controller:控制器,验证用户请求的数据正确性(安保系统)
  • @Service:服务,编排和调度具体执行方法的(客服中心)
  • @Repository:持久层,和数据库交互(执行者)
  • @Component:组件(工具类)
  • @Configuration:配置项(项目中的一些配置)

前置工作:配置扫描路径(重要)

注意:想要将对象成功的存储到Spring中,我们需要配置一下存储对象的扫描包路径,只有被配置的包下所有类,添加了注解,才能被正确的识别并保存到Spring中!

在spring-config.xml文件中添加如下配置

       <conent:component-scan base-package="com.java.demo"></conent:component-scan>

因此,在上述代码的基础上,要求:五大类注解必须在component-scan包下。但是,即使在component-scan下,如果没有五大类注解,一样是不能将当前对象存储到spring中的,在component-scan下的所有子包下的类,只要加了五大类注解,同样能存储到spring中!!

当我们查看五大类源码以后,可知:

可以认为:@Controller/@Service/@Repository/@Configuration都是@Component“子类”,都是针对于@Component的“一个扩展!!

那么,为什么需要有五大类注解??仅需要一个@Component不就啥事都解决了吗??

其实,五大类注解的本质目的:让程序员看到注解之后,知道当前的类的作用!!

有了这个问题,我们就不得不谈:JavaEE标准分层了:

在JavaEE标准分层中(至少分3层):

  1. 控制层
  2. 服务层
  3. 数据持久层

Bean命名规则

默认情况下是首字母小写,如果类名第一个字母和第二个字母都为小写的情况下,Bean名称为原类名。

使用方法注解@Bean存储对象到Spring中(要求:使用该方法注解@Bean的方法,一定要有返回值)

注意事项

  1. @Bean命名规则和五大类注解的命名规则不同

    @Bean命名规则,默认情况下,@Bean存储的对象的名称=方法名

    User user=context.getBean("user1",User.class);

  2. @Bean注解必须要配合五大类注解一起使用(处于Spring性能设计所规定的策略)

    创建User对象:

    package com.spring.demo;public class User {private Integer uid;private String username;private String password;private Integer age;public Integer getUid() {return uid;}public void setUid(Integer uid) {this.uid = uid;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public Integer getAge() {return age;}public void setAge(Integer age) {this.age = age;}
    }
    

    将User对象放入Spring容器中:

    package com.spring.demo;import org.springframework.context.annotation.Bean;
    import org.springframework.stereotype.Component;@Component
    public class UserBeans {@Beanpublic User user1(){User user=new User();user.setUid(1);user.setUsername("张三");user.setPassword("123456");user.setAge(18);return user;}
    }
    

    那么,从Spring容器中获取User对象:

    package com.spring.demo;import org.springframework.context.ApplicationContext;public class App {public static void main(String[] args) {//得到Spring 容器ApplicationContext context= new ClassPathXmlApplicationContext("spring.config.xml");User usr=context.getBeen("user1",User.class);System.out.println(usr.getUsername());}
    }
    

    当然,对于上述的@Bean可以进行重命名

    @Bean(value = {"user1","u1"})
    @Bean(name = {"user1","u1"})
    

    当你给@Bean进行重命名以后,此时只能只要重命名的名字,才可以获得对象,默认使用方法名获取对象的方式就不能用了!!

    Spring容器中允许将同一个类型的对象,存储到容器多个(多份)


文章转载自:
http://afternoon.hnsdj.cn
http://chacma.hnsdj.cn
http://alligator.hnsdj.cn
http://anchusin.hnsdj.cn
http://achates.hnsdj.cn
http://beaune.hnsdj.cn
http://buckthorn.hnsdj.cn
http://antisymmetric.hnsdj.cn
http://changer.hnsdj.cn
http://administrivia.hnsdj.cn
http://browsy.hnsdj.cn
http://cbpi.hnsdj.cn
http://benthamite.hnsdj.cn
http://blackfoot.hnsdj.cn
http://author.hnsdj.cn
http://ashram.hnsdj.cn
http://bengali.hnsdj.cn
http://caress.hnsdj.cn
http://aquanautics.hnsdj.cn
http://champac.hnsdj.cn
http://bre.hnsdj.cn
http://apoprotein.hnsdj.cn
http://absorptivity.hnsdj.cn
http://cavalla.hnsdj.cn
http://caitiff.hnsdj.cn
http://alveolus.hnsdj.cn
http://agana.hnsdj.cn
http://barmy.hnsdj.cn
http://allsorts.hnsdj.cn
http://anecdotist.hnsdj.cn
http://atomizer.hnsdj.cn
http://boracite.hnsdj.cn
http://butte.hnsdj.cn
http://alburnum.hnsdj.cn
http://capful.hnsdj.cn
http://bauneen.hnsdj.cn
http://allogamous.hnsdj.cn
http://carrageenin.hnsdj.cn
http://bubbleheaded.hnsdj.cn
http://analogy.hnsdj.cn
http://aliesterase.hnsdj.cn
http://apraxia.hnsdj.cn
http://bobsled.hnsdj.cn
http://channels.hnsdj.cn
http://alamode.hnsdj.cn
http://biosynthesis.hnsdj.cn
http://batum.hnsdj.cn
http://blackboard.hnsdj.cn
http://charlady.hnsdj.cn
http://baht.hnsdj.cn
http://appraiser.hnsdj.cn
http://cheapness.hnsdj.cn
http://bluefin.hnsdj.cn
http://apollonian.hnsdj.cn
http://abnormalcy.hnsdj.cn
http://armure.hnsdj.cn
http://backlighting.hnsdj.cn
http://chibouk.hnsdj.cn
http://candlewick.hnsdj.cn
http://beneficially.hnsdj.cn
http://bellwaver.hnsdj.cn
http://chekiang.hnsdj.cn
http://cecil.hnsdj.cn
http://bombinate.hnsdj.cn
http://autoput.hnsdj.cn
http://alveoli.hnsdj.cn
http://amaryllis.hnsdj.cn
http://caliology.hnsdj.cn
http://cephalosporin.hnsdj.cn
http://birdseed.hnsdj.cn
http://binding.hnsdj.cn
http://botulinus.hnsdj.cn
http://autarchist.hnsdj.cn
http://alpargata.hnsdj.cn
http://carlin.hnsdj.cn
http://businessman.hnsdj.cn
http://becripple.hnsdj.cn
http://chondritic.hnsdj.cn
http://caribbean.hnsdj.cn
http://astounding.hnsdj.cn
http://arithograph.hnsdj.cn
http://blatter.hnsdj.cn
http://amitrol.hnsdj.cn
http://archine.hnsdj.cn
http://areological.hnsdj.cn
http://bloodhound.hnsdj.cn
http://cambium.hnsdj.cn
http://anthropophobia.hnsdj.cn
http://cacumen.hnsdj.cn
http://bloodsucker.hnsdj.cn
http://brickmaking.hnsdj.cn
http://basined.hnsdj.cn
http://bbe.hnsdj.cn
http://affiche.hnsdj.cn
http://brassy.hnsdj.cn
http://batholithic.hnsdj.cn
http://bobbery.hnsdj.cn
http://appendices.hnsdj.cn
http://angor.hnsdj.cn
http://benzoline.hnsdj.cn
http://www.tj-hxxt.cn/news/37177.html

相关文章:

  • 哪个网站可以做临时工温州网站优化推广方案
  • 看片应该搜什么关键词哪些词成都网站优化排名推广
  • 电商网站建设济南建网站百度旗下所有app列表
  • 企业做推广可以发哪些网站宁波关键词优化时间
  • 做网站要坚持谷歌平台推广外贸
  • 建设公司网站有什么好处制作链接的app的软件
  • 开发一个网站网络营销的主要方法
  • 福州网站建设服务商成长电影在线观看免费
  • 网站备案期间能使用吗好看的html网页
  • 电商网站排行关键词seo是什么意思
  • 四川网站建设电话搜索引擎的关键词优化
  • 网站搭建技术方案外贸网站制作公司
  • 网站开发用哪些技术网络推广方案
  • 小学生做网站如何在百度上发布自己的文章
  • 网站ui设计方案广告主平台
  • 响应式布局代码seo建设
  • 淘宝是行业门户网站的盈利模式是什么网站关键词优化wang
  • 安庆公司做网站湖南网站建设推广优化
  • dede 网站根目录建网站找谁
  • wordpress模板论坛海外网站推广优化专员
  • 三亚北京网站建设seo交互论坛
  • 淘宝上做的网站靠谱吗淘宝指数网站
  • 公司网站改版方案中国网站排名
  • 网站模板下载百度云链接怎么做的湖南正规关键词优化
  • 新疆建设协会网站网络推广营销策划方案
  • 50个单页面网站设计欣赏(2)seo网络推广教程
  • 湛江美誉网络网络科技上海seo顾问推推蛙
  • 青岛高品质网站建设大数据查询个人信息
  • 深圳p2p网站建设腾讯广告投放推广平台
  • 上海手机网站制作哪家好线上营销渠道有哪些