1.创建实体
package org.zjh.openlayersdemo.entity;
import java.util.Date;
public class Dian {
private Integer id;
private Integer dNum;
private String dType;
private String dAddress;
private String dShape;
private String dName;
private String dPhone;
private Date dTime;
public Date getdTime() {
return dTime;
}
public void setdTime(Date dTime) {
this.dTime = dTime;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getdNum() {
return dNum;
}
public void setdNum(Integer dNum) {
this.dNum = dNum;
}
public String getdType() {
return dType;
}
public void setdType(String dType) {
this.dType = dType;
}
public String getdAddress() {
return dAddress;
}
public void setdAddress(String dAddress) {
this.dAddress = dAddress;
}
public String getdShape() {
return dShape;
}
public void setdShape(String dShape) {
this.dShape = dShape;
}
public String getdName() {
return dName;
}
public void setdName(String dName) {
this.dName = dName;
}
public String getdPhone() {
return dPhone;
}
public void setdPhone(String dPhone) {
this.dPhone = dPhone;
}
}
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 {
Dian selectAllById(Integer id);
}
3.创建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">
<mapper namespace="org.zjh.openlayersdemo.mapper.DianMapper">
<resultMap id="dianResultMap" type="org.zjh.openlayersdemo.entity.Dian" >
// 注意上面的type,与实体类全路径对应
<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>
// 注意下面的id与mapper接口里的方法名相同
<select id="selectAllById" resultType="org.zjh.openlayersdemo.entity.Dian">
select * from dian where id=#{id}
</select>
</mapper>
文件目录
4.application启动类里添加注解@MapperScan
package org.zjh.openlayersdemo;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
// 注意此处全路径
@MapperScan("org.zjh.openlayersdemo.mapper")
public class OpenlayersdemoApplication {
public static void main(String[] args) {
SpringApplication.run(OpenlayersdemoApplication.class, args);
}
}
5.application.yml添加配置
mybatis:
mapper-locations: classpath:mybatis/mapper/*Mapper.xml
type-aliases-package: org.zjh.openlayersdemo.entity
configuration:
# 驼峰命名
map-underscore-to-camel-case: true