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

可以建公司网站做一个公司官网怎么做

可以建公司网站,做一个公司官网怎么做,邯郸网络广播电视台,网站建设客户分析调查问卷优质博文#xff1a;IT-BLOG-CN 对于数据访问层#xff0c;无论是SQL还是NoSQL#xff0c;SpringBoot默认采用整合Spring Data的方式进行统一处理#xff0c;添加大量自动配置#xff0c;屏蔽了很多设置。引入各种xxxTemplate#xff0c;xxxRepository来简化我们对数据访… 优质博文IT-BLOG-CN 对于数据访问层无论是SQL还是NoSQLSpringBoot默认采用整合Spring Data的方式进行统一处理添加大量自动配置屏蔽了很多设置。引入各种xxxTemplatexxxRepository来简化我们对数据访问层的操作。对我们来说只需要进行简单的设置即可。 一、整合基本的 JDBC 与数据源 【1】引入jdbc starter [spring-boot-starter-jdbc] 和MySQL驱动。 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-jdbc/artifactId /dependency dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactIdscoperuntime/scope /dependency【2】在application.yml中配置数据源相关信息 spring:datasource:username: rootpassword: 123url: jdbc:mysql://127.0.0.1:3306/jdbcdriver-class-name: com.mysql.jdbc.Driver【3】测试默认使用的是org.apache.tomcat.jdbc.pool.DataSource作为数据源。数据源的相关配置都在DataSourceProperties里面。自动配置原理org.springframework.boot.autoconfigure.jdbc包中的DataSourceConfiguration根据配置创建数据源默认使用Tomcat连接池可以通过spring.datasource.type指定自定义数据源类型SpringBoot默认支持一下数据源DataSource、HikariDataSource、BasicDataSource。用户也可以自定义数据源如下可知是通过build创建数据源的。利用反射创建type类型的数据源并绑定相关属性。 ConditionalOnMissingBean({DataSource.class}) ConditionalOnProperty(name {spring.datasource.type} ) static class Generic {Generic() {}//通过 build 创建数据源的。利用反射创建 type 类型的数据源并绑定相关属性。Beanpublic DataSource dataSource(DataSourceProperties properties) {return properties.initializeDataSourceBuilder().build();} }【4】第二个比较重要的类DataSourceAutoConfiguration自动配置类中的dataSourceInitializer继承了ApplicationListener。 public class DataSourceAutoConfiguration {private static final Log logger LogFactory.getLog(DataSourceAutoConfiguration.class);public DataSourceAutoConfiguration() {}BeanConditionalOnMissingBeanpublic DataSourceInitializer dataSourceInitializer(DataSourceProperties properties, ApplicationContext applicationContext) {return new DataSourceInitializer(properties, applicationContext);}//...... }class DataSourceInitializer implements ApplicationListenerDataSourceInitializedEvent { //...... }DataSourceInitializer的两个主要作用①、运行建表语句②、运行操作数据的sql语句 //运行建表语句 private void runSchemaScripts() {ListResource scripts this.getScripts(spring.datasource.schema, this.properties.getSchema(), schema);if(!scripts.isEmpty()) {String username this.properties.getSchemaUsername();String password this.properties.getSchemaPassword();this.runScripts(scripts, username, password);try {this.applicationContext.publishEvent(new DataSourceInitializedEvent(this.dataSource));if(!this.initialized) {this.runDataScripts();this.initialized true;}} catch (IllegalStateException var5) {logger.warn(Could not send event to complete DataSource initialization ( var5.getMessage() ));}}} //运行操作数据的 sql语句 private void runDataScripts() {ListResource scripts this.getScripts(spring.datasource.data, this.properties.getData(), data);String username this.properties.getDataUsername();String password this.properties.getDataPassword();this.runScripts(scripts, username, password); }【5】进行数据表创建时默认只需要将文件命名为schema-*.sql进行数据操作时默认只需要将文件命令为data-*.sql如果自定义sql文件时可以在application.yml中通过如下方式指定sql文件位置传入的是一个list列表 spring:datasource:schema:- classpath: student.sql【6】JdbcTemplateAutoConfiguration自动配置类给容器中注入了JdbcTemplate组件帮组我们操作数据库。 AutoConfigureAfter({DataSourceAutoConfiguration.class}) public class JdbcTemplateAutoConfiguration {BeanPrimaryConditionalOnMissingBean({JdbcOperations.class})public JdbcTemplate jdbcTemplate() {return new JdbcTemplate(this.dataSource);} }【7】高级配置使用druid数据源首先需要引入依赖 !-- https://mvnrepository.com/artifact/com.alibaba/druid -- dependencygroupIdcom.alibaba/groupIdartifactIddruid/artifactIdversion1.1.10/version /dependency【8】在yml配置文件中加入Druid spring:datasource:username: rootpassword: 123url: jdbc:mysql://127.0.0.1:3306/jdbcdriver-class-name: com.mysql.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSource二、整合 Mybatis 数据源注解版 【1】创建项目选中web、mybatis、mysql和jdbc模块的starts在pom.xml中会发现mybatis与springboot的整合依赖这个依赖并不是以spring-boot开始的说明并不是spring提供的依赖而是由第三方mybatis提供的依赖包 dependencygroupIdorg.mybatis.spring.boot/groupIdartifactIdmybatis-spring-boot-starter/artifactIdversion2.1.1/version /dependency【2】定义个接口类用来操作目标表的增删改查通过Mapper表示该接口类是一个Mybatis的Mapper类通过增删改查注解Select Update Insert Delete对数据表进行操作 //指定这是一个操作数据库的 mapper Mapper public interface DepartmentMapper {Select(select * from department where id#{id})public Department getDeptById(Integer id); }【3】通过Controller层调用Server继而调用Mapper对数据完成操作 Controller public class DepartmentController {Autowiredprivate DepartmentMapper mapper;GetMapping(/dept/{id})public Department getDeptById(PathVariable(id) Integer id){return mapper.getDeptById(id);} }
http://www.hkea.cn/news/14400901/

相关文章:

  • 成都学生做网站机械加工网销平台
  • 临沂做网站的公司做网站工作室找客户难
  • 网站如何布局深圳网站和app建设
  • 开发网站公司的简介网站建设添加视频教程
  • 深圳模板网站建设设计公司关于网站制作的评价
  • 怎样在内网建设一个网站网站的购物车怎么做
  • 天津网站优化怎么样网站开发英语词汇
  • 西安网站设计开发如何用手机制作app课件
  • wordpress 整站语言广州 350建网站
  • 如何给网站增加关键词室内装修设计企业
  • 哈尔滨建设工程信息网官方网站佳易网页王
  • 公司建设网站需要去哪报备手机优化大师为什么扣钱
  • 郑州网站建设xinsu360福田企业网站优化有用吗
  • 微信公司网站免费网站建设方案优化
  • 南京网站建设网站制作网站批量修改
  • 主机建网站的优势国家高新技术企业含金量
  • 陕西住房城乡建设厅网站装修公司网络推广方案
  • 网站架设 数据库选用思源黑体可以做网站
  • 网站开发的好处和弊端深圳建网站一般多少钱
  • 免费网站模板无需注册android游戏开发教程
  • 杭州网站建设开发godaddy如何买wordpress
  • 企业微信网站建设方案舟山网站设计公司
  • 用户浏览网站的方式可以做空股票的网站
  • 怎么做网站推广图片河南网站建设设计价格
  • 男女做性哪个的小视频网站做酒店网站有哪些目录
  • 做网站的成本有多少钱东莞高端网站建设公司
  • 青岛君哲网站建设公司87网站一起做
  • 郑州做网站那做租赁哪个网站好
  • 企信网是什么网站wordpress more-link
  • 中国建设银行云南官网站纪念币怎样做网站规划