7_12Spring Boot+Mybaties+thymeleaf搭建环境
程序员文章站
2022-04-23 15:51:14
...
7_12Spring Boot+Mybaties+thymeleaf搭建环境
- 工具:Idea+Mysql5.6
idea新建Spring项目,加入Mybatis,项目结构如下:
pom.xml
<?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 http://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.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.li</groupId>
<artifactId>springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<!--mysql的版本-->
<mysql.version>5.1.47</mysql.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</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>
<version>2.0.1</version>
</dependency>
<!--Mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--mybatis代码生成器的插件-->
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.6</version>
<configuration>
<configurationFile>src/main/resources/mybatis/generator-config.xml</configurationFile>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
application.yml
server:
port: 8180
spring:
datasource:
url: jdbc:mysql://localhost:3306/test?useUnicode=yes&characterEncoding=UTF-8&useSSL=false
username: root
password: "0000"
driver-class-name: com.mysql.jdbc.Driver
mybatis:
#domain路径
type-aliases-package: com.li.springboot.domain
mapper-locations: classpath:/mybatis/mapper/*.xml
configuration:
#设置数据库中的字段例如s_name和getName
map-underscore-to-camel-case: true
- mybatis 代码生成器:加入Mybatis-generator-plugins
generator-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<context id="MySQLTables" targetRuntime="MyBatis3">
<!--Official Plugins-->
<!--Generate equals and hash code-->
<plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"/>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test?useUnicode=yes&characterEncoding=UTF-8&useSSL=false"
userId="root"
password="0000">
<property name="useInformationSchema" value="true"/>
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<javaModelGenerator targetPackage="com.li.springboot.domain" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources/mybatis">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.li.springboot.mapper" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<table schema="test" tableName="student" domainObjectName="Student">
</table>
</context>
</generatorConfiguration>
https://gitee.com/Marlon_Brando/springboot.git
chema="test" tableName="student" domainObjectName="Student">
</table>
</context>
</generatorConfiguration>
https://gitee.com/Marlon_Brando/springboot.git
推荐阅读
-
vue.js 2.*项目环境搭建、运行、打包发布的详细步骤
-
安卓开发环境配置有哪些方法,android开发环境的搭建步骤
-
netbeans环境中使用maven搭建jsf、primefaces工程
-
spring cloud 阿波罗 apollo 本地开发环境搭建过程
-
[微信公众平台开发]php开发环境搭建设置(一)
-
netbeans环境中使用maven搭建jsf、primefaces工程
-
在win7上hadoop环境搭建的方法(图)
-
windows环境下如何搭建Consul+Ocelot
-
java配置环境变量步骤(java开发环境的搭建方法)
-
详解OpenCV For Java环境搭建与功能演示