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

Mybatis如何给字段起别名?

Mybatis如何给字段起别名?

假如有一个学生表,有一个字段是class,你的实体类变量肯定不能用class,那么如何起别名?

通过以下代码实现

@Result(column = "class",property = "clas")

mapper代码

public interface StudentDao {@Insert("insert into student(id,name,sex,clas) values(#{name},#{money})")void save(Student student);@Update("upate student set name=#{name},sex=#{sex} where id=#{id}")void update(Student student);@Delete("delete from student where id=#{id}")void delete(String id);@Select("select * from student where id=#{id}")Student findById(String id);@Select("select * from student")@Result(column = "class",property = "clas")List<Student> findAll();
}

实体类

public class Student {public String getId() {return id;}public void setId(String id) {this.id = id;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public String getClas() {return clas;}public void setClas(String clas) {this.clas = clas;}@Overridepublic String toString() {return "Student{" +"id='" + id + '\'' +", name='" + name + '\'' +", sex='" + sex + '\'' +", clas='" + clas + '\'' +'}';}private String id;private String name;private String sex;private String clas;
}
http://www.lryc.cn/news/156628.html

相关文章:

  • php对接AWS S3云存储,上传S3及访问权限问题
  • java 实现单例模式
  • minio文件服务器开启https
  • 每日刷题(回溯法经典问题之子集)
  • PostgreSQL在进行除法时要注意
  • 开开心心带你学习MySQL数据库之第五篇
  • Geotools对geojson的解析
  • 【博客701】shell实现保留网络现场:ping失败时执行mtr
  • 放弃手写代码吧!用低代码你能生成各种源码
  • 什么程度才算精通 Linux?
  • jmeter中的__setProperty用法
  • vue基础知识六:v-show和v-if有什么区别?使用场景分别是什么?
  • SpringBoot几个常用的注解
  • 腾讯JAVA后端秋招面试总结
  • 随着iPhone 15降临,是时候扔掉所有的Lightning充电器了
  • huggingface 使用入门笔记
  • ASP.NET Core 中的 Razor Pages
  • C语言入门 Day_14 for循环
  • 深入解析 Socks5 代理与网络安全
  • Vue + Element UI 前端篇(十二):用户管理模块
  • C# 设计保存文件
  • Leetcode 1486.数组异或操作
  • 【Java】Java核心API概述
  • 微信小程序检查版本更新
  • Linux查看是虚拟机还是物理机
  • 【数据结构】二叉搜索树——二叉搜索树的概念和介绍、二叉搜索树的简单实现、二叉搜索树的增删查改
  • 通过linux定时任务删除es日志索引
  • 【跟小嘉学 Rust 编程】二十二、常用 API
  • 【ES6】Class中this指向
  • Python 编程竟然如此幽默!揭秘程序员们的搞笑日常,快来看看吧!