前言 前面参照SpringBoot官网,自动生成了简单项目点击打开链接 配置数据库和代码遇到的问题 问题1:cannot load driver class :com.mysql.jdbc.Driver不能加载mysql 原因:没有添加依赖 解决:pom.xml添加依赖 <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId></d…
大家在开发的时候,会喜欢jdbcTemplate操作数据库,有喜欢JPA操作数据库的,有喜欢MyBatis操作数据库的,对于这些我个人觉得哪个使用顺手就使用哪个就好了,并没有一定要使用哪个,个人在实际中会集成多个,这样保存的数据的时候,选择一个最方便的也就是JPA,查询的时候,或者统计的时候,选择一个效率最高的,也就是直接使用SQL语句方式,当然这并一定要这样的,现在优化方式又很多.那么这节说说怎么在Spring Boot中使用MyBatis吧.主要分几个步骤进行讲解: (1)新建maven p…
mybatis-config.xml是支持配置多种数据库的,本文将介绍在Spring Boot中使用配置类来配置. 1. 配置application.yml # mybatis配置 mybatis: check-config-location: false type-aliases-package: ${base.package}.model configuration: map-underscore-to-camel-case: true # 二级缓存的总开关 cache-enabled: f…
报出的错误 Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You…
//具体参看了配置的源码 org.springframework.boot.autoconfigure.amqp.RabbitProperties //RabbitMQ单机 spring:   rabbitmq:     host: localhost     port: 5672     username: your_username     password: your_password //或者 RabbitMQ单机,只使用addresses spring:   rabbitmq:    …
第一种写法resources目录下的application.properties文件 第二种写法resources目录下的application.yml文件 在项目中获取配置项: 分组配置:  (配置文件的格式 缩进 与冒号后的空格非常重要) 创建配置文件映射类 webConfigProperties private String title; private String foot; 空白处使用alt+insert快捷键 选择Getter and Setter可以快速生成get set方法 控…
配置类: @Configuration public class FeignConfiguration { @Bean(name="remoteRestTemplate") public RestTemplate RestTemplate(){ SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout(500…
1.在项目启动入口类实现 WebMvcConfigurer 接口: @SpringBootApplication public class Application implements WebMvcConfigurer { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } 2.重写 addCorsMappings 方法: @Override public voi…
内容简介 本文主要介绍在使用jpa向数据库添加数据时,如果表中主键为自增ID,对应实体类的设定方法. 实现步骤 只需要在自增主键上添加@GeneratedValue注解就可以实现自增,如下图: 关键代码: @GeneratedValue(strategy=GenerationType.IDENTITY) 有关注解的详细说明及用法,请参考: https://blog.csdn.net/u012493207/article/details/50846616…