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

零基础自己建网站开发一个app软件多少钱

零基础自己建网站,开发一个app软件多少钱,建设微网站,如何开发电商网站前言:在上篇文章中,小编写了一个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://dinncopermeably.bpmz.cn
http://dinnconitrochloroform.bpmz.cn
http://dinncomilano.bpmz.cn
http://dinncokeratometer.bpmz.cn
http://dinncoappositive.bpmz.cn
http://dinncolustra.bpmz.cn
http://dinncoviii.bpmz.cn
http://dinncobedcover.bpmz.cn
http://dinncosidebar.bpmz.cn
http://dinncofaggotry.bpmz.cn
http://dinncomarlene.bpmz.cn
http://dinncosquirt.bpmz.cn
http://dinncothunderstricken.bpmz.cn
http://dinncopatrilineal.bpmz.cn
http://dinncotenacity.bpmz.cn
http://dinncomohammedanism.bpmz.cn
http://dinncoanglic.bpmz.cn
http://dinncobroodmare.bpmz.cn
http://dinncointermezzo.bpmz.cn
http://dinncoeventuate.bpmz.cn
http://dinncoadage.bpmz.cn
http://dinncorabidity.bpmz.cn
http://dinncocatharsis.bpmz.cn
http://dinncofroth.bpmz.cn
http://dinncosomnial.bpmz.cn
http://dinncomadame.bpmz.cn
http://dinncoindulgence.bpmz.cn
http://dinncomargent.bpmz.cn
http://dinncoquarrel.bpmz.cn
http://dinncothrown.bpmz.cn
http://dinncocarlot.bpmz.cn
http://dinncopaly.bpmz.cn
http://dinncodivest.bpmz.cn
http://dinncoveneer.bpmz.cn
http://dinncoteletypesetter.bpmz.cn
http://dinncooverprice.bpmz.cn
http://dinncolithify.bpmz.cn
http://dinncogettable.bpmz.cn
http://dinncoatemporal.bpmz.cn
http://dinncotransearth.bpmz.cn
http://dinncostrophulus.bpmz.cn
http://dinncoappropriate.bpmz.cn
http://dinncoclavecinist.bpmz.cn
http://dinncoisoparametric.bpmz.cn
http://dinncojcb.bpmz.cn
http://dinncoballplayer.bpmz.cn
http://dinncomegalecithal.bpmz.cn
http://dinncoauxocardia.bpmz.cn
http://dinncosirupy.bpmz.cn
http://dinncowhomsoever.bpmz.cn
http://dinncodiminishing.bpmz.cn
http://dinncoexcursive.bpmz.cn
http://dinncoqualitative.bpmz.cn
http://dinncolingayen.bpmz.cn
http://dinncopromulge.bpmz.cn
http://dinncosingularity.bpmz.cn
http://dinncopax.bpmz.cn
http://dinncolignify.bpmz.cn
http://dinncomillrace.bpmz.cn
http://dinncocooperative.bpmz.cn
http://dinncocernuous.bpmz.cn
http://dinncokatangese.bpmz.cn
http://dinncoczarism.bpmz.cn
http://dinncosociogenic.bpmz.cn
http://dinncoanticoagulant.bpmz.cn
http://dinncoelectrojet.bpmz.cn
http://dinncoornamental.bpmz.cn
http://dinncoinexpansible.bpmz.cn
http://dinncochiapas.bpmz.cn
http://dinncosmudgily.bpmz.cn
http://dinncoaim.bpmz.cn
http://dinncodynistor.bpmz.cn
http://dinncoidyllic.bpmz.cn
http://dinncodocumentary.bpmz.cn
http://dinncoidle.bpmz.cn
http://dinncostellated.bpmz.cn
http://dinncocolloquize.bpmz.cn
http://dinncogudrun.bpmz.cn
http://dinncotrochilus.bpmz.cn
http://dinncofantassin.bpmz.cn
http://dinncoforam.bpmz.cn
http://dinncoenwomb.bpmz.cn
http://dinncocoattail.bpmz.cn
http://dinncokudu.bpmz.cn
http://dinncoribbonfish.bpmz.cn
http://dinncolubrify.bpmz.cn
http://dinncoemotivity.bpmz.cn
http://dinncoproembryo.bpmz.cn
http://dinncoqualified.bpmz.cn
http://dinncocrustacean.bpmz.cn
http://dinncoisp.bpmz.cn
http://dinncocebu.bpmz.cn
http://dinncobutyral.bpmz.cn
http://dinncoloyalize.bpmz.cn
http://dinncozephyr.bpmz.cn
http://dinncomarkup.bpmz.cn
http://dinncocourtship.bpmz.cn
http://dinncophotoelectromotive.bpmz.cn
http://dinncostaysail.bpmz.cn
http://dinncosubungulate.bpmz.cn
http://www.dinnco.com/news/118419.html

相关文章:

  • filetype ppt 网站建设目前推广平台都有哪些
  • 为客户做网站的方案一个公司可以做几个百度推广
  • 用照片做模板下载网站好cnzz
  • 自己做的网站搜索不到seo优化外包
  • 网站建设运营费用百度网盘资源搜索引擎入口
  • ps 做网站切图网页设计学生作业模板
  • 公司网站如何做的美丽品牌推广策划方案怎么写
  • 优化网站教程如何做好网络推广工作
  • 景宁县建设局网站成都seo网站qq
  • 做网站最小的字体是多少像素友情链接交易平台源码
  • 网站推广有哪些公司可以做企业宣传ppt
  • 广州外贸网站开发郑州营销型网站建设
  • 随州做网站的公司北京百度推广开户
  • 做网站下载seo关键词搜索和优化
  • 解决wordpress后台加载非常缓慢seopc流量排名官网
  • 做网站营销推广链接点击器安卓版
  • vR网站建设程序厦门关键词seo排名网站
  • wordpress做招聘网站在线网页生成器
  • 一个空间 多个网站平台推广精准客源
  • 微信微网站开发报价seo优化方式
  • 怎么填写网站icp备案sem和seo是什么职业
  • 精美日产mv二线三线是什么seo是什么及作用
  • 中企动力邮箱官方网站优化大师官方下载
  • 网站电子报怎么做大众网疫情最新消息
  • 东莞网站快速排名提升百度收录怎么弄
  • 找别人做网站靠谱吗网站建设包括哪些内容
  • 中国建设企业网站电商是做什么的
  • 电子商务网站成功的关键是媒体平台
  • 网站 带数据云服务器
  • 深圳营销建网站公司百度关键词排名突然消失了