具体实现详见我的上一篇博客:https://blog.csdn.net/qq_40983417/article/details/82344622
mysql作为免费的数据库拥有广泛的应用,也是我们学习数据库的最合适的第一试炼。
MySQL的application.properties的文件内容如下:
spring.datasource.url=jdbc:mysql://ip地址:端口号/库名
spring.datasource.username=用户名
spring.datasource.password=密码
spring.datasource.driverClassName=com.mysql.jdbc.Driver
mybatis.type-aliases-package=com.domain
mybatis.mapper-locations=classpath*:mapper/*Mapper.xml
logging.level.root=INFO
logging.level.org.springframework.web=INFO
logging.file=D:/scalDaily_Mysql.log
logging.pattern.console=%d{yyyy/MM/dd-HH:mm:ss} [%thread] %-5level %logger- %msg%n
logging.pattern.file=%d{yyyy/MM/dd-HH:mm:ss} [%thread] %-5level %logger- %msg%n
server.port=8380
与上一篇oracle的相比,最大的区别就是url的格式不同,当然,查询语句的写法也是不同的,这一点大家要根据自己的需求去查找资料。按照上一篇的demo,给出一个MySQL查询语句文件的示例:
UserMapper.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.dao.QueryMapper" >
<select id="getData" resultType="com.domain.Data" parameterType="String">
SELECT * FROM 表名 WHERE ( datediff ( 字段 , '${_parameter}' ) = 0 )
</select>
</mapper>
其中SELECT * FROM 表名 WHERE ( datediff ( 字段 , ‘${_parameter}’ ) = 0 )这一句是为了查询某一天的所有数据。其中日期格式的范例为"2018-09-18"。