• spring boot集成pg


    pom.xml


    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">
    4.0.0

    org.example
    pg-test
    1.0-SNAPSHOT


    8
    8
    UTF-8




    org.mybatis.spring.boot
    mybatis-spring-boot-starter
    2.1.4


    org.postgresql
    postgresql
    42.2.18


    org.projectlombok
    lombok
    RELEASE
    compile


    cn.hutool
    hutool-all
    5.7.16


    commons-cli
    commons-cli
    1.4



    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 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 findAll() {
    return fileContentMapper.findAll();
    }
    }

  • 相关阅读:
    HTML5新特性 day_04(8.10)地图、文件上传
    pytorch中使用多GPU并行训练
    案例:ELK日志分析系统
    前端事件案例补充
    python---面向对象(类和对象)
    数据挖掘实战(2)——糖尿病数据集(回归问题)
    驱动开发概念详解
    CNN进行猫狗识别(PyTorch)
    JAVAScript模块化设计
    TSINGSEE青犀视频AI方案:数据+算力+算法,人工智能的三大基石
  • 原文地址:https://blog.csdn.net/jmz10323/article/details/139485624