当前位置:   article > 正文

SpringBoot自动生成代码入门级教程

springboot自动生成代码

(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中添加 :

  1. mybatis.type-aliases-package=com.example.generalCode.dao
  2. mybatis.mapper-locations=classpath:mapper/*.xml

 2.无法识别各种注解 

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.7.0</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>com.example</groupId>
  12. <artifactId>generalCode</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>generalCode</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <java.version>1.8</java.version>
  18. </properties>
  19. <dependencies>
  20. <dependency>
  21. <groupId>org.springframework.boot</groupId>
  22. <artifactId>spring-boot-starter</artifactId>
  23. </dependency>
  24. <dependency>
  25. <groupId>org.springframework.boot</groupId>
  26. <artifactId>spring-boot-starter-test</artifactId>
  27. <scope>test</scope>
  28. </dependency>
  29. <dependency>
  30. <groupId>mysql</groupId>
  31. <artifactId>mysql-connector-java</artifactId>
  32. <version>5.1.48</version>
  33. </dependency>
  34. <dependency>
  35. <groupId>org.springframework.data</groupId>
  36. <artifactId>spring-data-commons</artifactId>
  37. <version>2.2.0.RELEASE</version>
  38. </dependency>
  39. <dependency>
  40. <groupId>org.springframework.boot</groupId>
  41. <artifactId>spring-boot-starter-web</artifactId>
  42. </dependency>
  43. <dependency>
  44. <groupId>org.mybatis.spring.boot</groupId>
  45. <artifactId>mybatis-spring-boot-starter</artifactId>
  46. </dependency>
  47. <dependency>
  48. <groupId>org.mybatis.spring.boot</groupId>
  49. <artifactId>mybatis-spring-boot-starter</artifactId>
  50. <version>1.2.0</version>
  51. </dependency>
  52. </dependencies>
  53. <build>
  54. <plugins>
  55. <plugin>
  56. <groupId>org.springframework.boot</groupId>
  57. <artifactId>spring-boot-maven-plugin</artifactId>
  58. </plugin>
  59. </plugins>
  60. </build>
  61. </project>

在报错不能识别 的 注解上ctrl+Enter自动补齐依赖 

3.interface上方不需要使用 mapper注解 ,在启动类上添加@MapperScan("com.example.generalCode.dao")即可 

  1. package com.example.generalCode;
  2. import org.mybatis.spring.annotation.MapperScan;
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. @SpringBootApplication
  6. @MapperScan("com.example.generalCode.dao")
  7. public class GeneralCodeApplication {
  8. public static void main(String[] args) {
  9. SpringApplication.run(GeneralCodeApplication.class, args);
  10. }
  11. }

最终目录结构如图 :

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/421945
推荐阅读
相关标签
  

闽ICP备14008679号