消息关闭
    暂无新消息!
初学mybatis+spring-boot整合,报错如下:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.nx.zhjf.mapper.UserMapper.findUserByUsername

我的代码结构如下:

application.ym配置文件如下:

spring:
  datasource:
    driver-class-name:org.postgresql.Driver
    url:jdbc:postgresql://localhost:5432/nx
    username:postgres
    password:postgres
#    schema:classpath:import.sql
  tomcat:
    max-active:30
    max-wait:1000
    max-idle:20
    remove-abandoned-timeout:180
mybatis:
  config-location:classpath:mybatis-config.xml



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.nx.zhjf.mapper.UserMapper">
    <insert id="save" parameterType="com.nx.zhjf.model.User">
        insert into t_user(username,age) values(#{userName,jdbcType=VARCHAR},#{age,jdbcType=NUMERIC})
    </insert>

    <select id="selectById" parameterType="java.lang.Integer" resultType="com.nx.zhjf.model.User">
        select * from t_user where id = #{id,jdbcType=NUMERIC}
    </select>

    <update id="updateById" parameterType="com.nx.zhjf.model.User">
        update t_user set
        username = #{userName,jdbcType=VARCHAR} ,
        age = #{age,jdbcType=NUMERIC}
        where id = #{id,jdbcType=NUMERIC}
    </update>

    <delete id="deleteById" parameterType="java.lang.Integer">
        delete from t_user where id = #{id,jdbcType=NUMERIC}
    </delete>

    <select id="findUserByUsername" parameterType="java.lang.String" resultMap="user">
        <bind name="pattern" value="'%' + username + '%'" />
        select * from t_user where username LIKE #{pattern}
    </select>

    <select id="count" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM t_user
    </select>

    <select id="queryAll" resultMap="user">
        select * from t_user
    </select>



</mapper>

UserMapper.java如下:

@Mapper
public interface UserMapper {
    int save(User user);

    User selectById(Integer id);

    int updateById(User user);

    int deleteById(Integer id);

    List<User> findUserByUsername(String username);

    int count();

    List<User> queryAll();
}


请大神帮我看下,哪里出问题了。




6个回答

︿ 2
  <mapper resource="com/nx/zhjf/mapper/UserMapper.xml"/>....这个写的有问题吧???
改为<mapper resource="com.nx.zhjf.mapper/UserMapper.xml"/>试试
︿ 0
你说的把/换成.我试过了,还是不行。
我的Service代码如下:
@Service
public class CityServiceImpl {

    @Autowired
    private CityMapper cityMapper;

    public City findById(long id) {
        return cityMapper.selectCityById(id);
    }
}
︿ 0
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>
    <typeAliases>
        <package name="com.nx.zhjf.model"/>
    </typeAliases>
    <mappers>
        <mapper resource="com/nx/zhjf/mapper/CityMapper.xml"/>
        <mapper resource="com/nx/zhjf/mapper/HotelMapper.xml"/>
        <mapper resource="com/nx/zhjf/mapper/UserMapper.xml"/>
    </mappers>
</configuration>