1.检查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="org.zjh.openlayersdemo.mapper.DianMapper">
// 注意下面type后为对应实体类全路径
<resultMap id="dianResultMap" type="org.zjh.openlayersdemo.entity.Dian" >
<id column="id" property="id" jdbcType="SMALLINT" />
<result column="d_num" property="dNum" jdbcType="SMALLINT" />
<result column="d_type" property="dType" jdbcType="VARCHAR" />
<result column="d_address" property="dAddress" jdbcType="VARCHAR"/>
<result column="d_shape" property="dShape" jdbcType="VARCHAR" />
<result column="d_name" property="dName" jdbcType="VARCHAR"/>
<result column="d_address" property="dAddress" jdbcType="VARCHAR"/>
</resultMap>
// 注意返回结果resultType为对象还是List,id是否与mapper接口中的方法名一致
<select id="selectAllById" resultType="org.zjh.openlayersdemo.entity.Dian">
select * from dian where id=#{id}
</select>
</mapper>
2.检查mapper接口
package org.zjh.openlayersdemo.mapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import org.zjh.openlayersdemo.entity.Dian;
import java.util.List;
@Mapper
public interface DianMapper {
// 注意方法名与xml中增删改查的id相对应
Dian selectAllById(Integer id);
}
3.检查application启动类
package org.zjh.openlayersdemo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
// 检查下面路径是否为xml文件路径
@MapperScan("org.zjh.openlayersdemo.mapper")
public class OpenlayersdemoApplication {
public static void main(String[] args) {
SpringApplication.run(OpenlayersdemoApplication.class, args);
}
}
4.检查application.yml配置文件
mybatis:
# 注意下面的路径
mapper-locations: classpath:mybatis/mapper/*Mapper.xml
type-aliases-package: org.zjh.openlayersdemo.entity
configuration:
# 驼峰命名
map-underscore-to-camel-case: true