spring boot集成pg

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>pg-test</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.18</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.16</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
</dependency>
</dependencies>

</project>

application.properties:

spring.profiles.active=dev

spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=xxxxxx
mybatis.type-aliases-package=com.aaa.model
mybatis.mapper-locations=classpath:mapper/*.xml

model:

import lombok.Data;

import java.time.OffsetDateTime;

@Data
public class FileContent {
private String id;
private OffsetDateTime created_at;
private OffsetDateTime updated_at;
private String content;
private String ip;
private String os;
private String path;
private String status;
}

mapper:

import com.aaa.FileContent;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FileContentMapper {
@Select("SELECT * FROM file_content")
List<FileContent> findAll();
}

FileContentService

import com.aaa.mapper.FileContentMapper;
import com.aaa.model.FileContent;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FileContentService {
private final FileContentMapper fileContentMapper;

public FileContentService(FileContentMapper fileContentMapper) {
this.fileContentMapper = fileContentMapper;
}

public List<FileContent> findAll() {
return fileContentMapper.findAll();
}
}

相关推荐

  1. spring boot集成pg

    2024-06-09 14:32:04       10 阅读
  2. springboot集成mybatis-plus

    2024-06-09 14:32:04       35 阅读
  3. springboot集成字典注解

    2024-06-09 14:32:04       42 阅读
  4. SpringBoot集成WebSocket

    2024-06-09 14:32:04       46 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-09 14:32:04       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-09 14:32:04       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-09 14:32:04       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-09 14:32:04       20 阅读

热门阅读

  1. !力扣70. 爬楼梯

    2024-06-09 14:32:04       9 阅读
  2. 微信小程序:实现音乐播放器的功能

    2024-06-09 14:32:04       6 阅读
  3. oracle10g的dataguard测试

    2024-06-09 14:32:04       12 阅读
  4. 电商系统中热库和冷库的使用与数据转换

    2024-06-09 14:32:04       8 阅读
  5. Python R用法:深度探索与实用技巧

    2024-06-09 14:32:04       9 阅读
  6. K-means聚类模型

    2024-06-09 14:32:04       10 阅读
  7. RAGFlow 学习笔记

    2024-06-09 14:32:04       10 阅读
  8. tcpdump 抓包

    2024-06-09 14:32:04       9 阅读
  9. TypeScript看这篇就够了

    2024-06-09 14:32:04       12 阅读
  10. 【分享】使用 Reducer 和 Context 拓展你的应用

    2024-06-09 14:32:04       13 阅读