springboot第十二天

springboot1.0,2014年发布,默认数据库连接池为 Tomcat JDBC Pool
springboot2.0,2018年3月1日发布,默认数据库连接池为  Hikari


1.项目创建选择组件:mysql,jdbc    web

application.yml里:

spring:
datasource:
username: root
password: root
#使用 MySQL连接驱动是8.0以上,需要在Url后面加上时区, GMT%2B8代表中国时区,不然报时区
错误
url: jdbc:mysql://127.0.0.1:3306/jdbc?serverTimezone=GMT%2B8
# 注意: 新版本驱动包,要使用以下类作为驱动类
driver-class-name: com.mysql.cj.jdbc.Driver


@RestController注解=@Controller+@ResponseBody

druid

<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
</dependency>

mybatis
创建项目    选择mybatis,jdbc,mysql   web


@MapperScan("com.mengxuegu.springboot.mapper")会自动装配指定包下面所有Mapper,省得在
每个Mapper上面写@Mapper

Mybatis官网: http://www.mybatis.org/mybatis-3/zh/index.html
mybatis通常用xml方式,小项目才用注解方式

在 resources 创建以下目录和核心配置文件mybatis-config.xml与mapper映射文件夹
mapper下一般装xxmapper.xml

mybatis-config.xml里加上驼峰映射
<configuration>
    <!--核心配置文件-->
    <settings>
        <setting name="mapUnderscoreToCamelCase" value="true"/>
    </settings>
</configuration>


application.yml里

#配置mybatis相关文件路径
mybatis:
  #映射配置文件路径
  mapper-locations: classpath:mybatis/mapper/*.xml
  #核心配置文件路径
  config-location: classpath:mybatis/mybatis-config.xml

IOexception
servletexception
SQLException
InterruptedException
MessagingException
UnknownHostException
RuntimeException

发布了97 篇原创文章 · 获赞 11 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/programmer188/article/details/104682695