若是Springboot项目,直接采用quickstart方式,创建的是一个以jar包方式对外提供统一输出的项目.
若不是springboot项目则采用第二种方式,创建的是一种可以以war包方式部署在tomcat或jboss这种web的j2ee容器里面.
<parent>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-parentartifactId>
<version>2.1.4.RELEASEversion>
parent>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
@SpringBootApplication(scanBasePackages = {"com.seckillproject"})
@RestController
@MapperScan("com.seckillproject.dao")
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
@EnableAutoConfiguration:将app这个启动类变成自动化可以支持springboot配置的bean,并且开启整个项目基于springboot的自动化配置,包括启动内嵌的tomcat并加载默认名配置
@SpringBootApplication:与@EnableAutoConfiguration效果相同,另外可以指定需要扫描的根目录包,能够通过注解的方式自动发现springboot特定的注解(@component,@service,@controller,@Repository).
@RestController:可以使用spring MVC的功能
@MapperScan:dao存放的地方
SpringApplication.run(App.class, args);:用于启动该springboot项目
引入mybatis相关依赖
<!--数据库:此connector是mysql的java client端-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<!--数据库连接池:用于管理mysql连接-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.3</version>
</dependency>
<!--Mybatis依赖:mybatis对springboot的支持文件-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
在application.properties中引入mybatis配置,用来启动带mybatis数据库访问的springboot项目
server.port=8080
mybatis.mapper-locations=classpath:mapping/*.xml
spring.datasource.name=seckill
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/seckill?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
<plugin>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-maven-pluginartifactId>
<version>1.3.5version>
<dependencies>
<dependency>
<groupId>org.mybatis.generatorgroupId>
<artifactId>mybatis-generator-coreartifactId>
<version>1.3.5version>
dependency>
<dependency>
<groupId>mysqlgroupId>
<artifactId>mysql-connector-javaartifactId>
<version>5.1.41version>
dependency>
dependencies>
<executions>
<execution>
<id>mybatis generatorid>
<phase>packagephase>
<goals>
<goal>generategoal>
goals>
execution>
executions>
<configuration>
<verbose>trueverbose>
<overwrite>falseoverwrite>
<configurationFile>
src/main/resources/mybatis-generator.xml
configurationFile>
configuration>
plugin>
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="DB2Tables" targetRuntime="MyBatis3">
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/seckill"
userId="root"
password="root">
jdbcConnection>
<javaModelGenerator targetPackage="com.seckillproject.dataobject" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
<property name="trimStrings" value="true" />
javaModelGenerator>
<sqlMapGenerator targetPackage="mapping" targetProject="src/main/resources">
<property name="enableSubPackages" value="true" />
sqlMapGenerator>
<javaClientGenerator type="XMLMAPPER" targetPackage="com.seckillproject.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true" />
javaClientGenerator>
<table tableName="user_info" domainObjectName="UserDO"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false" >table>
context>
generatorConfiguration>
-utf-8不包含表情符号(数据库设计)
密码是加密的字符串,一般不和用户信息主表创建在一起.在企业级项目中,密码托管一般是另一个项目实现.至少在数据库级别,密码和用户信息需要分开存取