XML映射

resources包下xml:(必须和Mapper文件同包同名,创建时不能用.分割,换成/)

<?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">
//namespace属性与mapper接口全限定名一致
<mapper namespace="com.itheima.mapper.EmpMapper">
//id属性与mapper接口中的方法名一致,返回数据类型也要一致
    <select id="list" resultType="com.itheima.pojo.Emp">
        select * from emp
        where name like concat('%',#{name},'%')
          and gender=#{gender}
          and entrydate between #{begin} and #{end}
        order by update_time desc
    </select>
</mapper>

//前四行去入门_MyBatis中文网

==================================================================================================================================================

接口mapper文件:

package com.itheima.mapper;

import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {
    public List<Emp> list(String name, Short gender, LocalDate begin,LocalDate end);

}

==================================================================================================================================================

SpringbootMybatisCrudApplication启动类:
package com.itheima;

import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@SpringBootTest
class SpringbootMybatisCrudApplicationTests {
@Autowired
    private EmpMapper empMapper;

@Test
    public void testList(){
     List<Emp> empList= empMapper.list("张",(short)1,LocalDate.of(2010,1,1),LocalDate.of(2020,1,1));
    System.out.println(empList);
    }

}

==================================================================================================================================================

出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not fou****)问题仔细检查xml是否与mapper接口同包同名,namespace属性与mapper接口全限定名是否一致,id属性与mapper接口中的方法名一致,返回数据类型也要一致。

或者查看target是否编译了xml文件

如果没有,在pom.xml添加

<!-- 如果不添加此节点src/main/java目录下的所有配置文件都会被漏掉。 -->
<resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.xml</include>
        </includes>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <includes>
            <include>**/*.xml</include>
            <include>**/*.properties</include>
            <include>**/*.ini</include>
        </includes>
    </resource>
</resources>

  • 8
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值