编辑
2023-05-08
Java
00
请注意,本文编写于 598 天前,最后修改于 598 天前,其中某些信息可能已经过时。

目录

entity
dao
service
controller

entity

  • 需要加的注解
java
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor @AllArgsConstructor @TableName("device") public class BK_DEVICE { /** * 主键 */ @ApiModelProperty(hidden = true) @TableId(type = IdType.AUTO) private Integer pid; /** * 设备类型 */ @ApiModelProperty(value = "设备类型", example = "W3RCB1") private String category; ... }

dao

  • 代码注意
    BaseMapper<对应实体类>
  • @Select(=#{数据库字段名})
  • @Param("数据库字段名")
java
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.nqdl.nqdliot.model.entity.BK_DEVICE; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import org.springframework.stereotype.Component; @Component public interface BKDeviceDao extends BaseMapper<BK_DEVICE> { /** 获取网关类型 */ @Select("SELECT `gtype` FROM `device` WHERE `gno` = #{gno}") String getGatewayType(@Param("gno") String gno); }
  • 对应mapper.xml文件
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.dao.BKDeviceDao"> <update id="方法名"> update db_talkativeplan.t_account set wechat=#{wechat} where uid=#{uid} </update> <update id="方法名"> update db_talkativeplan.t_account set qq=#{qq} where uid=#{uid} </update> <select id="方法名" resultType="com..entity.Account"> select * from t_account where uid=#{uid} </select> </mapper>

service

controller