赞
踩
(1)单击“Create New Project”:
(2)选择Maven并单击Next
(3)填写GroupId和ArtifactId,并点击Next,如下图所示:
(4)填写项目名称和需要存放的路径,并点击Finish,如下图所示:
(3)安装自动生成代码插件
然后重启IDEA
(4)配置数据库
(5)生成代码
选中某张表 ,右键 EasyCode->generate code ,全部勾选框即可生成xml,dao,entity,controller
常见问题 :
1.无法识别bean
application.properties中添加 :
- mybatis.type-aliases-package=com.example.generalCode.dao
- mybatis.mapper-locations=classpath:mapper/*.xml
2.无法识别各种注解
- <?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.7.0</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
- <groupId>com.example</groupId>
- <artifactId>generalCode</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <name>generalCode</name>
- <description>Demo project for Spring Boot</description>
- <properties>
- <java.version>1.8</java.version>
- </properties>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.48</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.data</groupId>
- <artifactId>spring-data-commons</artifactId>
- <version>2.2.0.RELEASE</version>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- </dependency>
- <dependency>
- <groupId>org.mybatis.spring.boot</groupId>
- <artifactId>mybatis-spring-boot-starter</artifactId>
- <version>1.2.0</version>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
- </project>
在报错不能识别 的 注解上ctrl+Enter自动补齐依赖
3.interface上方不需要使用 mapper注解 ,在启动类上添加@MapperScan("com.example.generalCode.dao")即可
- package com.example.generalCode;
-
- import org.mybatis.spring.annotation.MapperScan;
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
-
- @SpringBootApplication
- @MapperScan("com.example.generalCode.dao")
- public class GeneralCodeApplication {
-
- public static void main(String[] args) {
- SpringApplication.run(GeneralCodeApplication.class, args);
- }
-
- }
最终目录结构如图 :
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。