IDEA项目使用SpringBoot+MyBatis-Plus的方法

步骤如下:

1.打开IDEA

2.File—>new—> project

3.选择spring initializr—>Next

在这里插入图片描述

4.填写Grouphe和Artifact,选择Java version: 8 ,点击next ,如图:

在这里插入图片描述

5.选择对应的依赖,点击Next

在这里插入图片描述

6.核对项目的名字是否一致,点击finish后就完成了工程的创建。

在这里插入图片描述

7.接下来就是pom文件的依赖包引入了(很重要!!!)

<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.73</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-aop</artifactId>
    </dependency>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>ojdbc6</artifactId>
      <version>11.2.0.4.0-atlassian-hosted</version>
    </dependency>
    <!--   orail8n字符集  -->
    <dependency>
      <groupId>cn.easyproject</groupId>
      <artifactId>orai18n</artifactId>
      <version>11.2.0.4</version>
    </dependency>
    <!--    mybatis plus-->
    <dependency>
      <groupId>com.baomidou</groupId>
      <artifactId>mybatis-plus-boot-starter</artifactId>
      <version>3.3.1.tmp</version>
    </dependency>
    <!--    代码生成-->
    <dependency>
      <groupId>com.baomidou</groupId>
      <artifactId>mybatis-plus-generator</artifactId>
      <version>3.3.0</version>
    </dependency>
    <!--    代码生成模板-->
    <dependency>
      <groupId>org.apache.velocity</groupId>
      <artifactId>velocity-engine-core</artifactId>
      <version>2.2</version>
    </dependency>
    <!--   swagger  -->
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger2</artifactId>
      <version>2.9.2</version>
    </dependency>
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-ui</artifactId>
      <version>2.9.2</version>
    </dependency>
    <!--   lombok-->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.12</version>
    </dependency>

8.在appliaction.propertiles配置文件中写入数据库参数

spring.datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=用户
spring.datasource.password=密码
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

9.在Java下创建对应的pojo和mapper包,并创建对应的类

在这里插入图片描述

10.在pojo包中新建和数据库userinfo表映射的类

@Data
@KeySequence("SEQ_USER_INFO")
public class UserInfo {

  @TableId(value = "http://www.cppcns.com/ruanjian/java/USER_ID",type = IdType.INPUT)//在自增主键的变量加上即可
  private Long userId;
  private String userName;
  @TableField(value = "http://www.cppcns.com/ruanjian/java/USER_NINAME") //可以不写,但字段名要用小驼峰命名
  private String userNiName;
  private String userPwd;
  private Date userCtime;
  private Integer userState;
  private Integer userSex;
  private String userEdu;
  private String userPro;
  private String userEmail;
  private String userTel;
  private Long userScore;
}

IDEA项目使用SpringBoot+MyBatis-Plus的方法

扫一扫手机访问