要注册这两个文件

Mapper.xml文件中的namespace与mapper接口的全限定名相同

1、关联-association 集合-collection
2、所以association是用于一对一和多对一,而collection是用于一对多的关系
3、JavaType和ofType都是用来指定对象类型的
JavaType是用来指定pojo中属性的类型
ofType指定的是映射到list集合属性中pojo的类型。
mybatis当中最后只有mapper.xml和mapper 的interface 没有mapper的实现类了,直接使用接口映射操作数据库,它上层封装了service进行对mapper的使用。而service还有实现类也就是impl因为那是自己定义的
记录一下第一次,也是唯一一次手写的xml,mapper,service
service
public interface TStationService extends IService<TStation> {public T_StationVO getStationInfoBySID(); //得到充电站的信息,联合查询public int addStation(TStationDTO tStation);public List<T_StationVO> getAllShareStation();public int getAllStationCount(String cdz); //获得全部充电站数量public T_StationVO getStationById(Integer ID);public T_StationVO getStationInfoById(Integer S_ID); //根据充电站编号得到充电站具体信息public int updateStation(TStationDTO tStationDTO); //更新充电站信息public int OperatorCount(String OID); //得到一个客服修改充电站的数目public int getStationStateCount(Integer SID,Integer state); //某电站下处于忙状态的电桩个数}
mapper
package com.tjpu.echargeboot.mapper;import com.baomidou.mybatisplus.annotation.SqlParser;import com.baomidou.mybatisplus.extension.plugins.pagination.Page;import com.tjpu.echargeboot.DTO.TStationDTO;import com.tjpu.echargeboot.entity.TStation;import com.baomidou.mybatisplus.core.mapper.BaseMapper;import com.tjpu.echargeboot.vo.T_StationVO;import java.util.List;/*** <p>* Mapper 接口* </p>** @author zhizekai* @since 2020-10-31*/public interface TStationMapper extends BaseMapper<TStation> {public int addStation(TStationDTO tStation); //添加新的充电站// public List<T_Station> AllStation(Page page, String orderBy, String SC, String cdz); //得到所有充电站的列表// public List<T_Station> AllStation(Page page); //得到所有充电站的列表// public List<T_Station> AllStation(Page page,String address); //得到所有充电站的列表// public List<T_Station> AllStation(); //无分页public List<T_StationVO> getAllShareStation();public int getAllStationCount(String cdz); //获得全部充电站数量public T_StationVO getStationById(Integer ID);public T_StationVO getStationInfoById(Integer S_ID); //根据充电站编号得到充电站具体信息public int updateStation(TStationDTO tStationDTO); //更新充电站信息public int OperatorCount(String OID); //得到一个客服修改充电站的数目public int getStationBusyPileCount(Integer SID); //某电站下处于忙状态的电桩个数public int getStationReleasePileCount(Integer SID); //某电站下处于空闲状态的电桩个数public int getStationOfflinePileCount(Integer SID); //某电站下处于离线状态的电桩个数}
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.tjpu.echargeboot.mapper.TStationMapper"><!--增加一条充电站信息--><insert id="addStation" parameterType="com.tjpu.echargeboot.DTO.TStationDTO">INSERT INTO t_station (S_Name,S_Longitude,S_Latitude,S_Address,S_Date,O_ID,C_ID,S_FR,S_RepairTel,S_CompanyTel,S_ProDetail)VALUES (#{S_Name}, #{S_Longitude}, #{S_Latitude}, #{S_Address}, #{S_Date}, #{O_ID}, #{C_ID}, #{S_FR},#{S_RepairTel}, #{S_CompanyTel}, #{S_ProDetail})</insert><!--按照id查询充电站所有信息--><!--查询所有充电站信息--><resultMap id="TStationVOMap" type="com.tjpu.echargeboot.vo.T_StationVO"><id column="S_ID" jdbcType="INTEGER" property="S_ID"/><result column="S_Name" jdbcType="VARCHAR" property="S_Name"/><result column="S_Longitude" jdbcType="DECIMAL" property="S_Longitude"/><result column="S_Latitude" jdbcType="DECIMAL" property="S_Latitude"/><result column="S_Address" jdbcType="VARCHAR" property="S_Address"/><result column="S_Memo" jdbcType="VARCHAR" property="S_Memo"/><result column="S_ServiceType" jdbcType="INTEGER" property="S_ServiceType"/><result column="S_ServicePrice" jdbcType="REAL" property="S_ServicePrice"/><result column="S_Date" jdbcType="TIMESTAMP" property="S_Date"/><result column="S_RepairTel" jdbcType="VARCHAR" property="S_RepairTel"/><result column="S_CompanyTel" jdbcType="VARCHAR" property="S_CompanyTel"/><result column="S_ProDetail" jdbcType="VARCHAR" property="S_ProDetail"/><result column="S_Num" jdbcType="VARCHAR" property="S_Num"/><association property="t_feeRateVO" javaType="com.tjpu.echargeboot.vo.T_FeeRateVO"><id column="FR_ID" property="FR_ID"/><result column="FR_Name" property="FR_Name"/><result column="FR_1" property="FR_1"/><result column="FR_SPrice" property="FR_SPrice"/></association><association property="t_companyVO" javaType="com.tjpu.echargeboot.vo.T_CompanyVO"><id column="C_ID" property="C_ID"/><result column="C_Name" property="C_Name"/></association><association property="t_operatorVO" javaType="com.tjpu.echargeboot.vo.T_OperatorVO"><id column="O_ID" property="O_ID"/></association></resultMap><select id="getStationInfoById" parameterType="int" resultMap="TStationVOMap">SELECT A.*,B.C_Name,C.*FROM t_station A,t_company B,t_feerate CWHERE A.C_ID = B.C_IDAND A.S_FR = C.FR_IDAND A.S_ID = #{id}</select><!--查询分享充电站--><resultMap id="AllShareStationMap" type="com.tjpu.echargeboot.vo.T_StationVO"><id column="S_ID" jdbcType="INTEGER" property="S_ID"/><result column="S_Name" jdbcType="VARCHAR" property="S_Name"/><result column="S_Num" jdbcType="VARCHAR" property="S_Num"/><result column="S_Longitude" jdbcType="DECIMAL" property="S_Longitude"/><result column="S_Latitude" jdbcType="DECIMAL" property="S_Latitude"/><result column="S_Address" jdbcType="VARCHAR" property="S_Address"/><result column="S_Memo" jdbcType="VARCHAR" property="S_Memo"/><result column="S_Date" jdbcType="TIMESTAMP" property="S_Date"/><association property="t_operatorVO" javaType="com.tjpu.echargeboot.vo.T_OperatorVO"><result column="O_ID" jdbcType="VARCHAR" property="O_ID"/></association><association property="t_companyVO" javaType="com.tjpu.echargeboot.vo.T_CompanyVO"><result column="C_ID" jdbcType="INTEGER" property="C_ID"/><result column="C_Name" jdbcType="VARCHAR" property="C_Name"/></association></resultMap><select id="getAllShareStation" resultMap="AllShareStationMap">SELECT A.*,B.C_NameFROM t_station A,t_company Bwhere A.S_Type = 2And A.C_ID = B.C_ID</select><!--查询充电站数量--><select id="getAllStationCount" parameterType="string" resultType="int" >select count(*) AS cn from t_station<where><if test="cdz!=''">and t_station.S_Name=#{cdz}</if></where></select><update id="updateStation" parameterType="com.tjpu.echargeboot.DTO.TStationDTO">update t_station set S_Name=#{S_Name},S_Longitude=#{S_Longitude},S_Latitude=#{S_Latitude},S_Address=#{S_Address},O_ID=#{O_ID},C_ID=#{C_ID},S_FR=#{S_FR},S_RepairTel=#{S_RepairTel},S_CompanyTel=#{S_CompanyTel},S_ProDetail=#{S_ProDetail} where S_ID=#{S_ID}</update><!--某电站下处于忙状态的电桩个数--><select id="getStationBusyPileCount" parameterType="int" resultType="int">SELECTcount( 1 ) AS cnFROMt_station A,t_chgpile BWHEREA.S_ID = #{S_ID}AND A.S_ID = B.S_IDAND (B.CP_State = 2OR B.CP_State = 3)</select><!--某电站下处于空闲状态的电桩个数--><select id="getStationReleasePileCount" parameterType="int" resultType="int">SELECTcount( 1 ) AS cnFROMt_station A,t_chgpile BWHEREA.S_ID = #{S_ID}AND A.S_ID = B.S_IDAND B.CP_State =1</select><!--某电站下处于空闲状态的电桩个数--><select id="getStationReleasePileCount" parameterType="int" resultType="int">SELECTcount( 1 ) AS cnFROMt_station A,t_chgpile BWHEREA.S_ID = #{S_ID}AND A.S_ID = B.S_IDAND B.CP_State =1</select><!--某电站下处于离线状态的电桩个数--><select id="getStationOfflinePileCount" parameterType="int" resultType="int">SELECTcount( 1 ) AS cnFROMt_station A,t_chgpile BWHEREA.S_ID =#{S_ID}AND A.S_ID = B.S_IDAND (B.CP_State = 4OR B.CP_State = 5)</select></mapper>
