概述本项目使用的环境:开发工具:Intellij IDEA 2017.1.3springboot: 1.5.6jdk:1.8.0_161maven:3.3.9额外功能PageHelper 分页插件mybatis generator 自动生成代码插件步骤:1. 创建一个springboot项目:2. 创建项目的文件结构以及jdk的版本3. 选择项目所需要的依赖然后点击finish4. 看一下文件的结构:5. 查看一下pom.xml: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 http://maven.apache.org/xsd/maven-4.0.0.xsd">4 <modelVersion>4.0.0</modelVersion>56 <groupId>com.winter</groupId>7 <artifactId>springboot-mybatis-demo</artifactId>8 <version>0.0.1-SNAPSHOT</version>9 <packaging>jar</packaging>1011 <name>springboot-mybatis-demo</name>12 <description>Demo project for Spring Boot</description>1314 <parent>15 <groupId>org.springframework.boot</groupId>16 <artifactId>spring-boot-starter-parent</artifactId>17 <version>1.5.6.RELEASE</version>18 <relativePath/> <!-- lookup parent from repository -->19 </parent>2021 <properties>22 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>23 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>24 <java.version>1.7</java.version>25 </properties>2627 <dependencies>28 <dependency>29 <groupId>org.mybatis.spring.boot</groupId>30 <artifactId>mybatis-spring-boot-starter</artifactId>31 <version>1.3.0</version>32 </dependency>33 <dependency>34 <groupId>org.springframework.boot</groupId>35 <artifactId>spring-boot-starter-thymeleaf</artifactId>36 </dependency>37 <dependency>38 <groupId>org.springframework.boot</groupId>39 <artifactId>spring-boot-starter-web</artifactId>40 </dependency>4142 <dependency>43 <groupId>org.springframework.boot</groupId>44 <artifactId>spring-boot-starter-test</artifactId>45 <scope>test</scope>46 </dependency>47 <dependency>48 <groupId>mysql</groupId>49 <artifactId>mysql-connector-java</artifactId>50 <version>5.1.35</version>51 </dependency>525354 <dependency>55 <groupId>com.fasterxml.jackson.core</groupId>56 <artifactId>jackson-core</artifactId>57 </dependency>58 <dependency>59 <groupId>com.fasterxml.jackson.core</groupId>60 <artifactId>jackson-databind</artifactId>61 </dependency>62 <dependency>63 <groupId>com.fasterxml.jackson.datatype</groupId>64 <artifactId>jackson-datatype-joda</artifactId>65 </dependency>66 <dependency>67 <groupId>com.fasterxml.jackson.module</groupId>68 <artifactId>jackson-module-parameter-names</artifactId>69 </dependency>70 <!-- 分页插件 -->71 <dependency>72 <groupId>com.github.pagehelper</groupId>73 <artifactId>pagehelper-spring-boot-starter</artifactId>74 <version>1.1.2</version>75 </dependency>76 <!-- alibaba的druid数据库连接池 -->77 <dependency>78 <groupId>com.alibaba</groupId>79 <artifactId>druid-spring-boot-starter</artifactId>80 <version>1.1.0</version>81 </dependency>82 </dependencies>8384 <build>85 <plugins>86 <plugin>87 <groupId>org.springframework.boot</groupId>88 <artifactId>spring-boot-maven-plugin</artifactId>89 </plugin>90 <!-- mybatis generator 自动生成代码插件 -->91 <plugin>92 <groupId>org.mybatis.generator</groupId>93 <artifactId>mybatis-generator-maven-plugin</artifactId>94 <version>1.3.2</version>95 <configuration>96 <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>97 <overwrite>true</overwrite>98 <verbose>true</verbose>99 </configuration>100 </plugin>101 </plugins>102 </build>103104105 &
<div ID="article_content" data-pID="blog" data-mod="popu_307" data-dsm="post">
<h2 >本项目使用的环境:
<div ID="content_vIEws" >
开发工具:Intellij IDEA 2017.1.3springboot: 1.5.6href="https://www.baIDu.com/s?wd=jdk&tn=24004469_oem_dg&rsv_dl=gh_pl_sl_csd" target="_blank">jdk:1.8.0_161maven:3.3.9额外功能pageHelper 分页插件mybatis generator 自动生成代码插件步骤:
然后点击finish
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.winter springboot-mybatis-demo 0.0.1-SNAPSHOT jar springboot-mybatis-demo Demo project Spring Boot org.springframework.boot spring-boot-starter-parent 1.5.6.RELEASE UTF-8 UTF-8 1.7 org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.0 org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test MysqL mysql-connector-java 5.1.35 com.fasterxml.jackson.core jackson-core com.fasterxml.jackson.core jackson-databind com.fasterxml.jackson.datatype jackson-datatype-joda com.fasterxml.jackson.module jackson-module-parameter-names com.github.pageHelper pageHelper-spring-boot-starter 1.1.2 com.alibaba druID-spring-boot-starter 1.1.0 org.springframework.boot spring-boot-maven-plugin org.mybatis.generator mybatis-generator-maven-plugin 1.3.2 ${basedir}/src/main/resources/generator/generatorConfig.xml
将原有的resource文件夹下的application.propertIEs文件删除,创建一个新的application.yml配置文件,
文件的内容如下:
port: 8080 url: jdbc:MysqL: driver-- maxActive: 20 initialSize: 1 maxWait: 60000 minIDle: 1 timeBetweenevictionRunsMillis: 60000 minevictableIDleTimeMillis: 300000 valIDationquery: select 'x' testWhileIDle: testOnBorrow: testOnReturn: poolPreparedStatements: maxOpenPreparedStatements: 20 mapper-locations: classpath:mapPing
user_name VARCHAR(255 password VARCHAR(255 phone VARCHAR(255 ) ENGINE=INNODB auto_INCREMENT=1000 DEFAulT CHARSET=utf8;
配置pom.xml中generator 插件所对应的配置文件 ${basedir}/src/main/resources/generator/generatorConfig.xml PUBliC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> @H_957_502@ 点击run-Edit Configurations添加配置运行
注意!!!同一张表一定不要运行多次,因为mapper的映射文件中会生成多次的代码,导致报错,切记
最后生成的文件以及结构:
UserMapper.java
List }User.java
.userID = .username = username == ? .password = password == ? .phone = phone == ?