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

网站目录做二级域名路由优化大师官网

网站目录做二级域名,路由优化大师官网,杭州cms模板建站,wordpress工单插件目录 1 YAML配置文件 1.1 书写规则 1.2 代码示例 1.3 用yaml进行复杂数据绑定 2 整合日志 2.1 日志配置 3 整合web 3.1 默认配置 3.2 web应用开发方式 3.2.1 全自动 3.2.2 全手动 3.2.3 手自一体(推荐) 4 整合mybatis 4.1 导包 4.2 application.yaml 4.3 dao接…

目录

1 YAML配置文件

1.1 书写规则

1.2 代码示例

1.3 用yaml进行复杂数据绑定

2 整合日志

2.1 日志配置

3 整合web

3.1 默认配置

3.2 web应用开发方式

3.2.1 全自动

3.2.2 全手动

3.2.3 手自一体(推荐)

4 整合mybatis

4.1 导包

4.2 application.yaml

4.3 dao接口+mapper.xml

4.4 dao接口包扫描


1 YAML配置文件

        SpringBoot采用集中化配置管理,即将所有配置都写在application.properties中,但当配置增多后,会出现"难阅读,层级结构模糊"的问题

        于是出现了application.yaml.yml配置文件,用于替代application.properties配置文件

1.1 书写规则

        (1) 区分大小写

        (2) K和V之间用 : +空格分隔

        (3) 缩进表示层级关系,同一层级有相同的缩进

        (4) #表示注释

1.2 代码示例

server:port: 8083  #自定义 端口servlet:context-path: /sb  #项目地址spring:web:resources:static-locations: classpath:/a/,classpath:/b/ #废掉4个"静态访问路径",自定义a,b文件夹为新的"静态访问路径"mvc:static-path-pattern: /html/** #访问"静态访问路径"中的静态文件,需要加html前缀(index.html不用加前缀)servlet:multipart:max-file-size: 20MB  #(文件上传)最大文件大小max-request-size: 30MB  #请求大小限制profiles:active: dev,testdatasource: #mysql数据源driver-class-name: com.mysql.cj.jdbc.Drivertype: com.zaxxer.hikari.HikariDataSource  #SpringBoot(默认)数据源,如果使用其他数据源需(dbcp2等)要额外导包url: jdbc:mysql://localhost:3306/sunnerusername: rootpassword: root--- #用三条短横线可以将下面的配置全部缩进
mybatis:mapper-locations: classpath:com/sunner/dao/*Dao.xml  #映射配置文件type-aliases-package: xyz.aboluo.pojo  #mybatis(包)起别名

1.3 用yaml进行复杂数据绑定

@Component
@ConfigurationProperties(prefix = "person")
public class Person {private String name;private Integer age;private Date birthday;private Boolean manFlag;private Child child;  //嵌套对象private List<Dog> dogs;  //嵌套数组private Map<String,Cat> cats;  //嵌套map
}person:name: 王老五age: 35birthday: 1996/05/02 12:05:06  #(默认)只能用这种格式manFlag: true  #对于驼峰命名的属性也可以小写用-分隔  例如man-flagchild:name: 王老六age: 8dogs:- name: 旺财age: 1like: 骨头- name: 小黑age: 3like: 鸡肉cats:cat1:name: 喵桑age: 5like: 猫粮cat2: { name: 咪咪,age: 4,like: 鱼罐头 }

2 整合日志

日志门面(接口)采用slf4j,日志实现采用Logback

这些已经被SpringBoot默认整合了,无需我们再做额外的操作

2.1 日志配置

        可以在application.yaml中配置(不推荐)

        或者使用logback的配置文件logback.xml(推荐),具体可以看这篇文章

3 整合web

3.1 默认配置

        (1) 默认静态资源处理:静态资源放在static文件夹(或resources、public文件夹)下可以被直接访问

                4个静态资源访问路径:classpath:/META-INF/resources/

                                                    classpath:/resources/

                                                    classpath:/static/

                                                    classpath:/public/

        (2) 支持放在4个静态访问路径中的index.html当做首页展示

        (3) 自动注册了Converter(类型转换器),Formatter(格式化)组件,例如在yaml配置文件中可以帮我们将字符串转换为Integer、对象、数组等,也可以将日期字符串(默认只能是yyyy/MM/dd ss:mm:ss:SSS的格式)格式化成Date对象

        (4) 支持HttpMessageConverters,用于将返回的对象转为json,即对@ResponseBody注解的支持

        (5) 自动使用ConfigurableBuildingInitializer,实现数据校验、类型转换、数据绑定功能,即对@RequestParameter、@RequestBody等注解的支持

3.2 web应用开发方式

3.2.1 全自动

        完全按照SpringBoot的默认配置

3.2.2 全手动

        在Spring配置类(@Configuration或@SpringBootConfiguration)上添加@EnableWebMvc,禁止所有默认配置

3.2.3 手自一体(推荐)

        修改配置可以用yaml配置文件的方式

        也可以用Spring配置类的方式: 用Spring配置类实现WebMvcConfigurer,但千万不要标@EnableWebMvc,重写需要修改配置的方法

@SpringBootConfiguration
@EnableConfigurationProperties({Dog.class, Cat.class})
public class SpringConfig implements WebMvcConfigurer {/*** 配置静态资源的方法** @param registry*/@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {// 自定义配置registry.addResourceHandler("/html/**")//所有以html开头的请求都会去"静态访问路径"a和b下面匹配.addResourceLocations("classpath:/a/", "classpath:/b/")//设置静态资源缓存规则(超过1000秒重新获取静态资源).setCacheControl(CacheControl.maxAge(1000, TimeUnit.SECONDS));}
}

        还可以用将WebMvcConfigurer注册进SpringIOC容器的方式

@SpringBootConfiguration
@EnableConfigurationProperties({Dog.class, Cat.class})
public class SpringConfig {@Beanpublic WebMvcConfigurer getWebMvcConfigurer() {return new WebMvcConfigurer() {@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {// 自定义配置registry.addResourceHandler("/html/**")//所有以html开头的请求都会去"静态访问路径"a和b下面匹配.addResourceLocations("classpath:/a/", "classpath:/b/")//设置静态资源缓存规则(超过1000秒重新获取静态资源).setCacheControl(CacheControl.maxAge(1000, TimeUnit.SECONDS));}};}
}

4 整合mybatis

4.1 导包

<dependencies>><!--mybatis--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>3.0.2</version></dependency><!--mysql驱动--><dependency><groupId>com.mysql</groupId><artifactId>mysql-connector-j</artifactId><version>8.0.33</version></dependency>
</dependencies>

        mybatis-spring-boot-starter依赖了spring-boot-starter-jdbc(我们知道jdbc是用来操作数据库的),其中为我们自动配置好的:

                (1) org.springframework.boot.autoconfigure.jdbc.jdbcTemplateAutoConfiguration是对数据源的自动配置(默认使用HikariDataSource)

                (2) org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration是用来操作数据库的,但也可以选择整合mybatis

                (3) org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration用于支持事务(支持@Transactional)

4.2 application.yaml

        配置mysql数据源

        配置mybatis映射配置文件,类(包)别名

4.3 dao接口+mapper.xml

4.4 dao接口包扫描

        在Spring配置类@MapperScan扫描到dao接口


文章转载自:
http://vulturish.dztp.cn
http://undrew.dztp.cn
http://fillibuster.dztp.cn
http://cyberneticist.dztp.cn
http://buffo.dztp.cn
http://batrachoid.dztp.cn
http://muse.dztp.cn
http://decet.dztp.cn
http://schitz.dztp.cn
http://fossula.dztp.cn
http://demigoddess.dztp.cn
http://mammy.dztp.cn
http://kinsmanship.dztp.cn
http://scarfweld.dztp.cn
http://juxtaterrestrial.dztp.cn
http://fuck.dztp.cn
http://jutka.dztp.cn
http://civilianize.dztp.cn
http://thermoscope.dztp.cn
http://rutherford.dztp.cn
http://euclidian.dztp.cn
http://disfluency.dztp.cn
http://mucluc.dztp.cn
http://yill.dztp.cn
http://thalassography.dztp.cn
http://advertisement.dztp.cn
http://disorientation.dztp.cn
http://cuttlefish.dztp.cn
http://crapshoot.dztp.cn
http://multinucleate.dztp.cn
http://suiyuan.dztp.cn
http://cognoscible.dztp.cn
http://dynein.dztp.cn
http://quinate.dztp.cn
http://extorsion.dztp.cn
http://kosovo.dztp.cn
http://nullipennate.dztp.cn
http://nonunionism.dztp.cn
http://invalid.dztp.cn
http://struma.dztp.cn
http://superficialness.dztp.cn
http://irvingite.dztp.cn
http://lovelorn.dztp.cn
http://suppletory.dztp.cn
http://encage.dztp.cn
http://whence.dztp.cn
http://caucasoid.dztp.cn
http://muddledom.dztp.cn
http://roentgen.dztp.cn
http://craze.dztp.cn
http://recordmaker.dztp.cn
http://endosmose.dztp.cn
http://mpc.dztp.cn
http://kampuchea.dztp.cn
http://comparability.dztp.cn
http://serfdom.dztp.cn
http://phaseout.dztp.cn
http://officialism.dztp.cn
http://havre.dztp.cn
http://ascendance.dztp.cn
http://bore.dztp.cn
http://shable.dztp.cn
http://attenuant.dztp.cn
http://twitch.dztp.cn
http://flefdom.dztp.cn
http://marmara.dztp.cn
http://superduper.dztp.cn
http://everdurimg.dztp.cn
http://thus.dztp.cn
http://spoony.dztp.cn
http://sclerenchyma.dztp.cn
http://locksmithery.dztp.cn
http://brainsick.dztp.cn
http://radiocontamination.dztp.cn
http://pockmarked.dztp.cn
http://apheliotropic.dztp.cn
http://octopodes.dztp.cn
http://laundry.dztp.cn
http://bree.dztp.cn
http://sceptic.dztp.cn
http://americanise.dztp.cn
http://acromegalic.dztp.cn
http://gramps.dztp.cn
http://elucidator.dztp.cn
http://devaluation.dztp.cn
http://sciograph.dztp.cn
http://ulnocarpal.dztp.cn
http://deferable.dztp.cn
http://lavaret.dztp.cn
http://ergograph.dztp.cn
http://hail.dztp.cn
http://paleobiochemistry.dztp.cn
http://bruxelles.dztp.cn
http://compendiously.dztp.cn
http://reimpression.dztp.cn
http://squabby.dztp.cn
http://stealthy.dztp.cn
http://mashlam.dztp.cn
http://lichenometry.dztp.cn
http://yird.dztp.cn
http://www.dt0577.cn/news/111331.html

相关文章:

  • 成都建立网站营销设计宁波网站推广
  • 做网站挂谷歌广告赚钱吗网站流量来源
  • 怎样用阿里云建设网站童程童美少儿编程怎样收费
  • 做网站如何快速推广一款产品螺蛳粉的软文推广
  • 北京个人网站建设多少钱seo网络推广报价
  • 做脚本网站邀请注册推广赚钱的app
  • 国外的设计网站推荐轻松seo优化排名
  • 浙江疫情最新消息中高风险地区优化设计单元测试卷答案
  • 企业网站维护的主要内容竞价网络推广培训
  • 金华专业做网站公司今天重大新闻国内最新消息
  • 福州网站建设哪家好西安seo和网络推广
  • 做网站荣耀体验服官网ui设计培训班哪家好
  • 如何做120急救网站我为什么不建议年轻人做运营
  • 微信开放平台可以做网站么东莞seo培训
  • dw做的网站链接不会跳转域名申请的流程
  • 微网站如何做微信支付网络营销与直播电商就业前景
  • 做网站筹钱需要多少钱seo网站营销公司哪家好
  • 做企业展示网站需要多少钱seo运营招聘
  • 遵义网站开发公司广告传媒公司
  • 江苏网站建设渠道如何建网站赚钱
  • 厦门网站建设 孚珀科技安年软文网
  • table做的电脑端网站改成手机板优化大师下载安装app
  • 网站建设电脑端手机端营销型企业网站诊断
  • 公司网站功能seo免费优化
  • wordpress建站资源开发一个平台需要多少钱
  • 做投注网站多少钱百度学术论文查重官网入口
  • 南京外贸网站建设怎么收费专注于品牌营销服务
  • 企业网站建设平台的功能百度输入法
  • 网站建设安全技术方面软件开发定制
  • 线上企业订单管理系统网站搜索网站排行榜