SpringBoot框架 xml配置文件,和Application.yml配置文件实例

创建springboot项目所需依赖(最右侧)如下图:
在这里插入图片描述

Mapper.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">
<!--namesparce对应dao层的路径,id对应dao层方法名,resultType对应实体类路径,给dao层类上添加@Mapper注解-->
<mapper namespace="com.btrc.mapper.LogMapper">
    <select id="findAll" resultType="com.btrc.entity.Log">
        select * from log
    </select>

    <!--通过id查询-->
    <select id="findByLogId" resultType="com.btrc.entity.Log">
        SELECT * FROM log WHERE log_id = #{log_id}
    </select>

    <!--查询所有的最新数据-->
    <select id="findByMaxTime" resultType="com.btrc.entity.Log">
         select
    g2.*
from
    (select log_id,name,max(logal) logal from log group by log_id,name) g1
left join log g2
on g1.log_id = g2.log_id and g1.logal = g2.logal and g1.name = g2.name
    </select>



    <!--插入数据-->
    <insert id="insertLog" keyProperty="id" useGeneratedKeys="false">
      insert into log(id, log_id, name, logal, beginTime, overTime, status, time)
        values (#{id}, #{log_id}, #{name}, #{logal}, #{beginTime}, #{overTime}, #{status}, #{time})
    </insert>

    <!--条件查询根据时间查询-->
    <select id="findByStatusOrTime" resultType="com.btrc.entity.Log">
        select
        id,log_id, name, logal, beginTime, overTime, status, time
        from log
        <where>
            <if test="beginTime != '' and beginTime != null">
                and beginTime &gt;= #{beginTime,jdbcType=DATE}
            </if>
            <if test="overTime != '' and overTime != null">
                and overTime &lt;= #{overTime,jdbcType=DATE}
            </if>
            <if test="status != '' and status != null">
                and status = #{status}
            </if>
        </where>
    </select>

</mapper>

Application.propetites改名为Application.yml


 server:
   port: 9001
 spring:
   #数据库配置
   datasource:
     driver-class-name: com.mysql.cj.jdbc.Driver
     url: jdbc:mysql://127.0.0.1:3306/bigdata?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
     username: root
     password: root

#查找mapper.xml所在位置 一般在resources根目录下
 mybatis:
   mapper-locations: classpath:mapper/*.xml

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值