resources/application.yml
spring: datasource: username: root password: root #mysql8版本以上的驱动包,需要指定以下时区 url: jdbc:mysql://127.0.0.1:3306/table_name?serverTimezone=GMT%2B8 #mysql8版本以上指定新的驱动类 driver-class-name: com.mysql.cj.jdbc.Driver #引入Druid数据源 type: com.alibaba.druid.pool.DruidDataSource
#配置mybatis相关文件路径 mybatis: #映射配置文件路径 mapper-locations: classpath:mybatis/mapper/*.xml #核心配置文件路径 config-location: classpath:mybatis/mybatis-config.xml
resources/mybatis/mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!--核心配置文件--> <settings> <setting name="mapUnderscoreToCamelCase" value="true"/> </settings> </configuration>
resources/mybatis/mapper/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.company.project.mapper.UserMapper"> <select id="getUserByBid" resultType="com.company.project.entities.User"> select * from table_name where id=#{id} </select> <insert id="addBill"> insert into User(id,username, password) values(#{id}, #{username}, #{password}) </insert> <update id="updateUser"> update user set id=#{id}, username= #{username},password= #{password} where id=#{id} </update> <delete id="deteleUserByBid"> delete from user where id=#{id} </delete> </mapper>