Commit d3a585c2 by HanChao

增加 数据库连接 示例

parent 83ce353d
......@@ -32,16 +32,16 @@
<!-- MyBatis-Plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>mysql</groupId>-->
<!-- <artifactId>mysql-connector-java</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->
<!-- -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.gzicloud.industry.client.resume.dao;
import com.gzicloud.industry.client.resume.entity.ResumePO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ResumeMapper {
ResumePO getCountry(Long id);
}
package com.gzicloud.industry.client.resume.entity;
import lombok.Data;
@Data
public class ResumePO {
private Long id;
private String country;
}
package com.gzicloud.industry.client.resume.service.impl;
import com.gzicloud.industry.client.resume.dao.ResumeMapper;
import com.gzicloud.industry.client.resume.service.IResumeService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class ResumeServiceImpl implements IResumeService {
@Resource
private ResumeMapper resumeMapper;
@Override
public String getName(Long id) {
return "spring bean 类中返回的:" + id;
return "spring bean 类中返回的:" + resumeMapper.getCountry(id).getCountry();
}
}
......@@ -12,14 +12,19 @@ spring:
group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置
file-extension: yml #默认properties
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: hanchao
password: 123123
url: jdbc:mysql://localhost:3306/db2020?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8
hikari:
jdbc-url: jdbc:mysql://localhost:3306/db2020?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
username: hanchao
password: 123123
driver-class-name: com.mysql.cj.jdbc.Driver
minimum-idle: 10
maximum-pool-size: 20
connection-timeout: 2000
maximum-pool-size: 15
connection-timeout: 1000
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
mapper-locations: classpath:/mapper/*Mapper.xml
dubbo:
scan:
......
<?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="com.gzicloud.industry.client.resume.dao.ResumeMapper">
<select id="getCountry" parameterType="java.lang.Long" resultType="com.gzicloud.industry.client.resume.entity.ResumePO">
select id, country from t_country where id = #{id}
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment