当前位置: 首页 > news >正文

mybatisplus查询指定字段

使用mybatisplus查询指定字段
实体类

package com.test.entity;

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 com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.util.JSONPObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;


@TableName("student")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Student implements Serializable {
    @TableId(type = IdType.AUTO)
    private int id;
    private String name;
    /*@TableField(typeHandler = FastjsonTypeHandler.class)
    private JSONPObject param;*/
}

查询名称

package com.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.test.entity.Student;
import com.test.mapper.StudentMapper;
import com.test.service.StudentService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Resource
    StudentMapper studentMapper;
    @Override
    public ResponseEntity findNameById(Integer id) {
        QueryWrapper<Student> queryWrapper = new QueryWrapper<Student>().select("name");
        queryWrapper.eq("id",id);
        List<Object> objects = studentMapper.selectObjs(queryWrapper);
        return ResponseEntity.ok(objects);
    }
}

mapper层

package com.test.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.test.entity.Student;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface StudentMapper extends BaseMapper<Student> {
}

参考博客:
mybatisplus查询某一字段

相关文章:

  • Nginx 负载均衡+高可用 集群部署(Keepalived+LVS DR模式)
  • MongoDB基本语法
  • PowerShell脚本编写:自动化Windows开发工作流程实例介绍
  • Python 中考虑 concurrent.futures 实现真正的并行计算
  • C++学习笔记(8)
  • 【Unity-Lua】音乐播放器循环滚动播放音乐名
  • 【SpringBoot】使用Nacos服务注册发现与配置管理
  • MySQL库的操作
  • C++入门(04)命令行窗口
  • Golang | Leetcode Golang题解之第393题UTF-8编码验证
  • c语言和c++的区别
  • 网络编程之-UDP详解
  • 什么是 Java?Java 的主要特点有哪些?
  • 【WPF】WPF学习之【二】布局学习
  • leetcode 23.合并k个升序链表
  • JVM系列(十) -垃圾收集器介绍
  • 面试题.04
  • 【Python】数据可视化之分类图
  • 【Datawhale X 李宏毅苹果书 AI夏令营】《深度学习详解》Task3 打卡
  • EvoSuite使用总结
  • 外交部:习近平主席同普京总统达成许多新的重要共识
  • 无人机穿越大理千年古塔落券洞内,涉事“飞手”被行拘10日
  • 创新创业50人论坛开幕在即,双创青年为何选择来上海筑梦?
  • 新疆生产建设兵团草湖项目区副主任宋全伟接受审查调查
  • 重磅金融政策密集发布!一文梳理这场国新办发布会
  • 潘功胜:将下调个人住房公积金贷款利率0.25个百分点