SpringBoot - IDEA逆向生成Entity

前言

这里介绍IDEA根据数据库逆向生成Entity,数据库为Mysql。


具体实现

IDEA连接Mysql

  • View -》Tool Windows -》Database 调出Database面板
    在这里插入图片描述
  • “✚” -》Data Source -》数据库类型
    在这里插入图片描述
  • 新建数据源
    在这里插入图片描述
  • 连接建立如下:
    在这里插入图片描述

逆向生成Entity

  • View -》Tool Windows -》Persistence调出Persistence面板
  • 注:Persistence面板找不到看文章最后一节
    在这里插入图片描述
  • 项目右键 -》Generate Persistence Mapping -》By Database Schema
    在这里插入图片描述
  • 选择数据源、生成包目录、勾选需要生成的数据表,点击OK
    在这里插入图片描述
  • 生成结果如下
    在这里插入图片描述

Persistence面板调出

注: 在View -》Tool Windows -》中找不到Persistence面板时可根据如下步骤调出:

  • 点击View -》Project Structure,调出Project Structure面板。
  • 在调出Project Structure面板的项目名上右键 -》Add -》JPA ,给项目添加JPA模块。
  • 在JPA面板中下方的Default JPA Provider选项选择JPA的提供者Hibernate,点击OK。

- End -
- 个人学习笔记 -
- 仅供参考 -

  • 4
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
以下是使用Spring Boot结合MyBatis和Alibaba Druid连接池对ClickHouse进行数据操作的步骤: 1.在pom.xml文件中添加ClickHouse JDBC驱动和Alibaba Druid连接池的依赖: ```xml <dependency> <groupId>ru.yandex.clickhouse</groupId> <artifactId>clickhouse-jdbc</artifactId> <version>0.3.1</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.10</version> </dependency> ``` 2.在application.properties文件中配置ClickHouse和Druid的连接信息: ```properties # ClickHouse 数据库连接配置 spring.datasource.url=jdbc:clickhouse://localhost:8123/default spring.datasource.driver-class-name=ru.yandex.clickhouse.ClickHouseDriver spring.datasource.username=username spring.datasource.password=password # Druid 连接池配置 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.initial-size=1 spring.datasource.min-idle=1 spring.datasource.max-active=20 spring.datasource.max-wait=60000 spring.datasource.time-between-eviction-runs-millis=60000 spring.datasource.min-evictable-idle-time-millis=300000 spring.datasource.validation-query=SELECT 1 FROM DUAL spring.datasource.test-while-idle=true spring.datasource.test-on-borrow=false spring.datasource.test-on-return=false spring.datasource.pool-prepared-statements=true spring.datasource.max-pool-prepared-statement-per-connection-size=20 spring.datasource.filters=stat,wall,log4j spring.datasource.connection-properties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 ``` 3.在Spring Boot的启动类上添加注解@EnableTransactionManagement和@MapperScan: ```java @SpringBootApplication @EnableTransactionManagement @MapperScan("com.example.demo.mapper") public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } ``` 4.创建Mapper接口和对应的XML文件,使用MyBatis进行数据操作: ```java @Mapper public interface UserMapper { @Select("SELECT * FROM user") List<User> selectAll(); } ``` ```xml <mapper namespace="com.example.demo.mapper.UserMapper"> <resultMap id="BaseResultMap" type="com.example.demo.entity.User"> <id column="id" property="id" jdbcType="INTEGER"/> <result column="name" property="name" jdbcType="VARCHAR"/> <result column="age" property="age" jdbcType="INTEGER"/> </resultMap> <select id="selectAll" resultMap="BaseResultMap"> SELECT * FROM user </select> </mapper> ``` 5.在Controller中注入Mapper并进行数据操作: ```java @RestController public class UserController { @Autowired private UserMapper userMapper; @GetMapping("/users") public List<User> getUsers() { return userMapper.selectAll(); } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Maggieq8324

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值