idea2023根据表自动生成+springboot跑起来

  1. idea安装插件
    idea2023根据表自动生成+springboot跑起来_第1张图片
  2. idea中显示数据库连接

idea2023根据表自动生成+springboot跑起来_第2张图片
idea2023根据表自动生成+springboot跑起来_第3张图片
idea2023根据表自动生成+springboot跑起来_第4张图片
就可以看到如下界面
idea2023根据表自动生成+springboot跑起来_第5张图片
选中你想生成的表,右键如下操作
idea2023根据表自动生成+springboot跑起来_第6张图片
idea2023根据表自动生成+springboot跑起来_第7张图片
idea2023根据表自动生成+springboot跑起来_第8张图片
如上就有了所有需要的后端代码

生成后,要查看一下mapper.xml中的文件是否 正确,若有误请先去修改,例如我的版本下生成了xml文件中缺乏逗号
4. 如上写好后想跑起来,配置pom,xml


<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.7.16version>
        <relativePath/> 
    parent>
    <groupId>com.ztgroupId>
    <artifactId>shopartifactId>
    <version>0.0.1-SNAPSHOTversion>
    <name>shopname>
    <description>shopdescription>
    <properties>
        <java.version>1.8java.version>
    properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-thymeleafartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>

        <dependency>
            <groupId>com.mysqlgroupId>
            <artifactId>mysql-connector-jartifactId>
            <scope>runtimescope>
        dependency>
        <dependency>
            <groupId>org.projectlombokgroupId>
            <artifactId>lombokartifactId>
            <optional>trueoptional>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
        
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-data-jpaartifactId>
            <version>3.1.4version>
        dependency>
        
        <dependency>
            <groupId>org.mybatis.spring.bootgroupId>
            <artifactId>mybatis-spring-boot-starterartifactId>
            <version>2.2.2version>
        dependency>


    dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombokgroupId>
                            <artifactId>lombokartifactId>
                        exclude>
                    excludes>
                configuration>
            plugin>
        plugins>
    build>

project>

  1. 配置application.properties
server.port=8081

spring.datasource.url=jdbc:mysql://localhost:3306/ssm
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

mybatis.mapper-locations=classpath:mapper/*.xml
  1. 修改 启动器类,增加dao层扫描
    idea2023根据表自动生成+springboot跑起来_第9张图片

  2. 如此就可以正常启动项目访问了
    idea2023根据表自动生成+springboot跑起来_第10张图片

你可能感兴趣的:(spring,boot,后端,java)