spring boot 整合 mybatis


我踩过的坑希望你们重新踩一遍

1, dao层(Mapper)——>service——>controller(控制层)

             |                              | (impl)                      |   

  对应Mapper.xml             注入dao层(Mapper)        注入service


2

出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)的解决方法    原因:没有找到方法及Mapper那个包,查看自己的mapper.xml文件,看一下 <mapper namespace="com.bk.Mapper.userMapper"> 是否与项目中mapper包名字一样,大小写敏感。推荐你们使用逆向工程。


application.yml 文件

spring:

  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/lyb?useUnicode=true&characterEncoding=UTF-8
    username: root
    password: 7788521  
    type: com.alibaba.druid.pool.DruidDataSource
    connectionProperties: druid.stat.mergeSql=true
   
mybatis:
      typeAliasesPackage: com.bk.entity
      mapperLocations: classpath:mapper/*.xml

      #config-location: 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.bk.Mapper.userMapper">
  <resultMap id="BaseResultMap" type="com.bk.entity.User">
    <result column="id" jdbcType="DECIMAL" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
  </resultMap>
  <insert id="insert" parameterType="com.bk.entity.User">
    <selectKey keyProperty="id" order="BEFORE" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into user (id, name)
    values (#{id,jdbcType=DECIMAL}, #{name,jdbcType=VARCHAR})
  </insert>
  <select id="selectAll" resultMap="BaseResultMap">
    select id, name
    from user
  </select>
</mapper>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值