SpringBoot + MyBatis 配置mapper.xml

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

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值