发表于: 2019-12-27 20:46:14
4 944
啥也不说就是干!!!
今天完成的事情:
1、数据库三大范式
第一范式(1NF)每一列都是不可分割的原子数据项
第二范式(2NF)在 1NF 的基础上,非码属性必须完全依赖于码(1NF基础上消除非主属性对主码的部分函数依赖)
1)函数依赖:A->B 如果通过 A 属性(属性组)的值,可以确定唯一 B 属性的值,则称 B 依赖于 A
例如:学号 -> 姓名 (学号、课程名称)-> 分数
2)完全函数依赖:A -> B,如果 A 是一个属性组,则 B 属性值的确定需要依赖于 A 属性组中所有的属性值
例如:(学号、课程名称)-> 姓名
3)部分依赖:A -> B,如果 A 是一个属性组,则 B 属性值的确定只需要依赖 A 属性组中某一些值即可
例如:(学号、课程名称)-> 姓名
4)传递函数依赖 A -> B,B -> C,如果通过 A 属性(属性组)的值,可以确定唯一 B 属性的值,在通过 B 属性(属性组)的值可以确定唯一 C 属性 值,则称 C 传递依赖 A
5)码:如果在一张表中,一个属性或属性组,被其他所有属性所完全依赖,则称这个属性(属性组)为该表的码
例如:该表中码为:(学号、课程名称)
主属性:码属性组中的所有属性
非主属性:除过吗属性组的属性
第三范式(3NF):在 2NF 基础上,任何非主属性不依赖于其他非主属性(2NF 基础上消除传递依赖)
2、查看垂伦小室的产品资料(PPT,原型图,禅道)
1)分析所需实体类,理清楚它们之间的关系及各个实体类所需要的字段
2)根据实体类创建数据表及索引
Category 目录分类表
会按照父级分类查询二级分类,在 parentId 字段上面创建索引
CREATE INDEX p_index ON category (parentId);
Article 作品表
会按照 categoryId 查找作品,在 categoryId 字段上创建索引
CREATE INDEX category_index ON article (categoryId);
会按照作品名查找作品,在 name 字段上创建索引
CREATE INDEX name_index ON article (name(30));
Comment 评论表
会按照 articleId 查找评论,在 articleId 字段上创建索引
CREATE INDEX article_index ON comment (articleId);
Reply 回复表
会按照评论 id 查找回复,在 commentId 字段上创建索引
CREATE INDEX comment_index ON reply(commentId);
Author 作者表
会根据作者姓名查找作者,在 name 字段上创建索引
CREATE INDEX name_index ON author(name);
Banner 轮播表
数据量不大,不创建索引
ImageInfo 配图表
会根据分类及类型查找图片路径,在relationId 和 type 字段上创建组合索引
CREATE INDEX type_index ON imageInfo(relationId,type)
3、MybatisGenerator 根据数据库,生成代码
1、配置 Mybatis-Generator Maven 插件
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
<!--mybatis的代码生成器的配置文件-->
<configurationFile>src/main/resources/mybatis-generator-config.xml</configurationFile>
<!--允许覆盖生成的文件-->
<overwrite>true</overwrite>
<!--将当前pom的依赖项添加到生成器的类路径中-->
<!--<includeCompileDependencies>true</includeCompileDependencies>-->
</configuration>
<dependencies>
<!--mybatis-generator插件的依赖包-->
<!--<dependency>-->
<!--<groupId>org.mybatis.generator</groupId>-->
<!--<artifactId>mybatis-generator-core</artifactId>-->
<!--<version>1.3.7</version>-->
<!--</dependency>-->
<!-- mysql的JDBC驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
</dependencies>
</plugin>
2、配置 mybatis-generator-config.xml
<generatorConfiguration>
<!--导入属性配置-->
<properties resource="db.properties"></properties>
<context id="testTables" targetRuntime="MyBatis3">
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
<jdbcConnection driverClass="${druid.driverClassName}"
connectionURL="${druid.url}"
userId="${druid.username}"
password="${druid.password}">
</jdbcConnection>
<!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
NUMERIC 类型解析为java.math.BigDecimal -->
<javaTypeResolver>
<property name="forceBigDecimals" value="false" />
</javaTypeResolver>
<!-- targetProject:生成PO类的位置 -->
<javaModelGenerator targetPackage="com.gerry.jnshu.pojo"
targetProject="src/main/java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
<!-- 从数据库返回的值被清理前后的空格 -->
<property name="trimStrings" value="true" />
</javaModelGenerator>
<!-- targetProject:mapper映射文件生成的位置 -->
<sqlMapGenerator
targetPackage="mapper"
targetProject="src/main/resources">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- targetPackage:mapper接口生成的位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.gerry.jnshu.mapper"
targetProject="src/main/java">
<!-- enableSubPackages:是否让schema作为包的后缀 -->
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<table schema="" tableName="article" domainObjectName="Article"
enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
enableUpdateByExample="false" selectByExampleQueryId="false">
<!--是否使用实际列名,默认为false-->
<!--<property name="useActualColumnNames" value="false" />-->
</table>
<table schema="" tableName="author" domainObjectName="Author"
enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
enableUpdateByExample="false" selectByExampleQueryId="false">
<!--是否使用实际列名,默认为false-->
<!--<property name="useActualColumnNames" value="false" />-->
</table>
<table schema="" tableName="banner" domainObjectName="BannerInfo"
enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
enableUpdateByExample="false" selectByExampleQueryId="false">
<!--是否使用实际列名,默认为false-->
<!--<property name="useActualColumnNames" value="false" />-->
</table>
<table schema="" tableName="category" domainObjectName="CategoryInfo"
enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
enableUpdateByExample="false" selectByExampleQueryId="false">
<!--是否使用实际列名,默认为false-->
<!--<property name="useActualColumnNames" value="false" />-->
</table>
<table schema="" tableName="comment" domainObjectName="Comment"
enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
enableUpdateByExample="false" selectByExampleQueryId="false">
<!--是否使用实际列名,默认为false-->
<!--<property name="useActualColumnNames" value="false" />-->
</table>
<table schema="" tableName="reply" domainObjectName="Reply"
enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
enableUpdateByExample="false" selectByExampleQueryId="false">
<!--是否使用实际列名,默认为false-->
<!--<property name="useActualColumnNames" value="false" />-->
</table>
</context>
</generatorConfiguration>
3、命令行执行 mvn mybatis-gnerator:generate 生成代码
明天计划的事情:
1、继续学习 Mybatis-Generator
2、设计接口,编写接口文档
遇到的问题:
无
收获:
学习了数据库三大范式,配置 mybatis-generator
评论