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

北京海淀社保网站网页设计与网站建设完全实用手册

北京海淀社保网站,网页设计与网站建设完全实用手册,平台app如何推广,上海网站建设 公司案例配置文件最主要的目的 : 解决硬编码的问题(代码写死) SpringBoot 的配置文件,有三种格式 1.properties 2.yaml 3.yml(是 yaml 的简写) SpringBoot 只支持三个文件 1.application.properties 2.application.yaml 3.application.yml yaml 和 yml 是一样的,学会一个就行…配置文件最主要的目的 : 解决硬编码的问题(代码写死) SpringBoot 的配置文件,有三种格式 1.properties  2.yaml 3.yml(是 yaml 的简写) SpringBoot 只支持三个文件  1.application.properties 2.application.yaml 3.application.yml yaml 和 yml 是一样的,学会一个就行 如果一个项目中同时存在 properties 和 yml ,虽然两个都会生效,但是 properties 的优先级更高 但是正常情况下都只有一个文件,多了容易乱 properties 的代码格式一般为键值对的样式,以 分割,单词小写,单词之间用 . 分割 下面是一些配置举例,配置端口号和配置数据库先不细说 我们自定义的配置该如何拿到运用呢? 我们创建一个类 package com.example.ioc.controller;import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController public class PropertiesController {//读取配置文件Value(${demo.key1})private String key1;RequestMapping(/readkey)public String readkey(){return 读取到的配置项key1key1;} } 就能成功拿到了 名字一一对应 什么样的内容适合放在配置文件中呢? 那些可能会发生改变的信息,与我的程序运行没有太大关系的,我们就把它放在配置文件中 但是其实我们发现 properties 有很多冗余的信息 比如 想要解决这个问题,就可以使用 yml 配置文件的格式化了 我们先在 resources 底下创建一个文件,application.yml yml 文件对比 properties 文件格式,yml 文件把 . 换成冒号换行,key后面用冒号赋值 这样就可以把端口改为 9090 了 但是我们稍作修改,把9090 前面的空格删掉,再次运行程序,发现修改端口失败了 yml 的格式有严格要求,我们要在值前面的冒号的后面加空格,空格不可省略 我们对数据库相关配置进行修改的样式如下 yml 的自定义配置该如何写并且使用呢? 然后创建一个类 package com.example.ioc.controller;import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;RestController public class YmlController {Value(${demo.key1})public String key1;RequestMapping (/readYml)public String readYml(){return key1;} } 这样就能成功使用了 我们再看看多个数据 PostConstruct//这是一个初始化注解,在属性注入完成之后就会执行这个方法 package com.example.ioc.controller;import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import javax.annotation.PostConstruct;RestController public class YmlController {Value(${demo.key1})public String key1;Value(${demo.key2})public String key2;Value(${demo.key3})public String key3;RequestMapping (/readYml)public String readYml(){return key1;}PostConstruct//这是一个初始化注解,在属性注入完成之后就会执行这个方法public void init(){System.out.println(key1:key1);System.out.println(key2:key2);System.out.println(key3:key3);} } 我们再看看单双引号的区别 双引号里面的 \n 是换行 单引号会对特殊字符进行转义,因为\n 本身表示的意思是换行,但是使用单引号的时候,内容变成了 \n 而不是换行,所以认为是转义 yml 该如何配置对象? 配置文件为 再创建一个student类 package com.example.ioc;import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;Component ConfigurationProperties(prefix student) Data public class Student {private Integer id;private String name;private Integer age; } 然后就能运行了  package com.example.ioc.controller;import com.example.ioc.Student; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import javax.annotation.PostConstruct;RestController public class YmlController {Autowiredpublic Student student;PostConstruct//这是一个初始化注解,在属性注入完成之后就会执行这个方法public void init(){System.out.println(student:student);} } yml 如何配置集合呢? package com.example.ioc.model;import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;import java.util.List;Component ConfigurationProperties(prefix dbtypes) Data public class DBTypes {private ListString name; } package com.example.ioc.controller;import com.example.ioc.model.DBTypes; import com.example.ioc.model.Student; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import javax.annotation.PostConstruct;RestController public class YmlController {Autowiredpublic DBTypes dbTypes;PostConstruct//这是一个初始化注解,在属性注入完成之后就会执行这个方法public void init(){System.out.println(dbTypes:dbTypes);} } 用数组去接收也是可以滴 记得要加空格哦 yml 也可以配置map import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;import java.util.HashMap; import java.util.List;Component ConfigurationProperties(prefix dbtypes) Data public class DBTypes {private ListString name;private HashMapString,String map; } package com.example.ioc.controller;import com.example.ioc.model.DBTypes; import com.example.ioc.model.Student; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import javax.annotation.PostConstruct;RestController public class YmlController {Autowiredpublic DBTypes dbTypes;PostConstruct//这是一个初始化注解,在属性注入完成之后就会执行这个方法public void init(){System.out.println(dbTypes:dbTypes);} } yml 的优缺点 :
http://www.hkea.cn/news/14383931/

相关文章:

  • 杭州哪家做外贸网站好已有域名如何在花生壳网站做二级域名托管
  • 做企业评价的有哪些网站平台搭建是什么
  • 阿里云有网站建设吗北京市通信管理局 网站备案
  • 网站推广关键词工具泸州市住房和城乡建设局网站
  • 网站标题被别人改了 应该怎么办苏宁易购
  • 商家在网站做淘宝客会给佣金吗做网站用什么语言制作最安全
  • 公司网站建设推荐可视化拖拽建站系统
  • 衡水做wap网站价格公司做网站的费用怎么做账
  • 宝山网站建设哪家好wordpress 导航函数
  • 做一手楼房的网站织梦手机网站源码
  • 做古风头像的网站平台优化是指什么
  • 阳江网站推广优化公司网络营销专业是学什么的
  • 网站建设信息公开和解读回应大设计师论坛网页设计
  • 珠海网站建设小程序uc浏览器手机网页版
  • 上海黄浦 网站制作咸宁网站建设多少钱
  • 游戏软件开发培训学校枣庄做网站优化
  • 建云购网站企业服务专员
  • 深圳便宜的网站建设东莞常平新楼盘有哪些
  • 用新华做网站名是否侵权潍坊市网站建设公司
  • 天津 网站策划南昌企业网站开发公司
  • 如何做 试题类 网站网站建设技术员分为前端 后端
  • 本地安装网站无法连接数据库帝国cms做淘宝客网站
  • 网站建设所需的硬件设备产品推广软文
  • 网站被百度k了如何申述百度惠生活
  • 一个网站域名ip小程序云开发教程
  • 计算机网站开发与技术专业介绍网页跟网站的区别
  • 企业网站的设计与实现网页游戏手机怎么玩
  • 企业网站建设课件建设银行网站 个人客户端
  • 可以看qq空间的网站苏州 建设 公司 手机
  • 什么是竞价百度推广怎么做网站的优化