Description
If you shed tears when you miss the sun, you also miss the stars.
演示的视频见以下网址: https://www.bilibili.com/video/BV1St4y1p7nD (opens new window)
项目仓库: https://github.com/DevinWain/water-extractor (opens new window)
后续:
后续:
后续:
后续:
后续:
主要记录一下流程:
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>
<configuration>
<!-- mybatis-generator的配置文件,根据情况调整位置 -->
<configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<executions>
<execution>
<id>Generate MyBatis Artifacts</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</plugin>
<?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>
<!--JDBC驱动jar包的 路径 -->
<classPathEntry location="src/main/resources/mysql-connector-java-8.0.13.jar"/>
<!--defaultModelType="flat" 大数据字段,不分表 -->
<context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<property name="autoDelimitKeywords" value="true" />
<property name="javaFileEncoding" value="utf-8" />
<!-- 生成序列化ID-->
<plugin type="org.mybatis.generator.plugins.SerializablePlugin" />
<plugin type="org.mybatis.generator.plugins.ToStringPlugin" />
<!-- 注释 -->
<commentGenerator >
<property name="suppressAllComments" value="true"/><!-- 是否取消注释 -->
<property name="suppressDate" value="true" /> <!-- 是否生成注释代时间戳-->
</commentGenerator>
<!--数据库链接地址账号密码-->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/water_photo?serverTimezone=Asia/Shanghai"
userId="root"
password="123456">
</jdbcConnection>
<!-- 类型转换 -->
<javaTypeResolver>
<!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) -->
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--生成Model类存放位置-->
<javaModelGenerator targetPackage="com.wain.server.domain" targetProject="src/main/java">
<property name="enableSubPackages" value="false"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator>
<!-- 生成mapxml文件 -->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources" >
<property name="enableSubPackages" value="false" />
</sqlMapGenerator>
<!-- 生成mapxml对应client,也就是接口dao -->
<javaClientGenerator targetPackage="com.wain.server.dao" targetProject="src/main/java" type="XMLMAPPER" >
<property name="enableSubPackages" value="false" />
</javaClientGenerator>
<!-- 指定生成代码的数据表 -->
<table tableName="photolist" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
<!-- <generatedKey column="id" sqlStatement="Mysql" identity="true" />-->
</table>
<!-- <table tableName="user_role" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">-->
<!-- <generatedKey column="id" sqlStatement="Mysql" identity="true" />-->
<!-- </table>-->
</context>
</generatorConfiguration>
dao上加入@Mapper注解(Mybatis官方推荐)
在启动类上配置:
@MapperScan("com.wain.server.dao")
同时在dao上加入@Repository注解(Mybatis不推荐)
mybatis.typeAliasesPackage=com.wain.server.domain
mybatis.mapperLocations=classpath:mapper/*.xml
这里用了service层来测试,实际上可以用dao层做测试,具体参考《疯狂Spring Boot终极讲义》P301
@RunWith(SpringRunner.class)
@SpringBootTest
class ServerApplicationTests {
@Autowired
private PhotoServiceImpl photoService;
@Test
void testPhotoService() {
Photolist photo = new Photolist();
photo.setUrl("/src/hello");
photo.setCreatetime(new Date());
System.out.println(photoService.addPhoto(photo));
}
}
html的img标签在src的url未更新的情况下是不会刷新图片的,也就是说,哪怕你的后台图片变了,只要url不变,那么前端展示的图片就不变。
解决方案:
在url中加入查询参数,可以指定为时间戳,从而保证每次url不一致。如:\img\1.png?23123123123。
Invalid bound statement (not found)错误的可能原因:https://www.bilibili.com/read/cv4957285 (opens new window)
一分钟带你学会利用mybatis-generator自动生成代码:https://zhuanlan.zhihu.com/p/91985133 (opens new window)
This app can be installed on your PC or mobile device. This will allow this web app to look and behave like any other installed app. You will find it in your app lists and be able to pin it to your home screen, start menus or task bars. This installed web app will also be able to safely interact with other apps and your operating system.
If you shed tears when you miss the sun, you also miss the stars.