标签:har png ash iba jdb ace private where 连接池
前言:基于springboot,使用mysql数据库,druid连接池
引入依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.14</version>
</dependency>
配置application.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/easy_mybatis? serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8
username: root
password: ccc+022599
type: com.alibaba.druid.pool.DruidDataSource
mybatis:
type-aliases-package: cn.ccb.pojo
mapper-locations: classpath:mapper/*.xml
编写实体类、mapper接口、mapper映射文件
@Repository
@Mapper
public interface UserMapper {
public User queryUserByName(String name);
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable {
private String username;
private String password;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.ccb.mapper.UserMapper">
<select id="queryUserByName" resultType="user" parameterType="string">
select * from userinfo where username=#{name}
</select>
</mapper>
标签:har png ash iba jdb ace private where 连接池
原文地址:https://www.cnblogs.com/codeccb/p/12615669.html