MyBatis中的几种注解映射
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MyBatis中的几种注解映射相关的知识,希望对你有一定的参考价值。
参考技术A 原文链接:http://blog.csdn.net/naruto_mr/article/details/482074371.普通映射
@Select("select * from mybatis_Student where id=#id")
public Student getStudent(int id);
@Insert("insert into mybatis_Student (name, age, remark, pic,grade_id,address_id) values (#name,#age,#remark, #pic,#grade.id,#address.id)")
public int insert(Student student);
@Update("update mybatis_Student set name=#name,age=#age where id=#id")
public int update(Student student);
@Delete("delete from mybatis_Student where id=#id")
public int delete(int id);
2.结果集映射
@Select("select * from mybatis_Student")
@Results(
@Result(id=true,property="id",column="id"),
@Result(property="name",column="name"),
@Result(property="age",column="age")
)
public List getAllStudents();
3.关系映射
3.1一对一
@Select("select * from mybatis_Student")
@Results(
@Result(id=true,property="id",column="id"),
@Result(property="name",column="name"),
@Result(property="age",column="age"),
@Result(property="address",column="address_id",one=@One(select="com.skymr.mybatis.mappers.AddressMapper.getAddress"))
)
public List getAllStudents();
3.2一对多
@Select("select * from mybatis_grade where id=#id")
@Results(
@Result(id=true,column="id",property="id"),
@Result(column="grade_name",property="gradeName"),
@Result(property="students",column="id",many=@Many(select="com.skymr.mybatis.mappers.Student2Mapper.getStudentsByGradeId"))
)
public Grade getGrade(int id);
mybatis 批量增删改查操作的几种操作以及创建数据库索引
参考技术A 1、批量插入操作mapper.java层定义:
int batchInsert(List stockList);
mapper.xml层的sql语句:
insert into t_stock (status, asset_classify_id,asset_id,asset_item_id, name,num, batch_num, tag_id,rfid, epc, barcode,qr_code, erp, unit,pic_url, specification, model,material, color,length,width, height, weight,density, volume, price01,price02,warehouse_id, storage_zone_id,storage_location_id,storage_location_tag_id,remark, attr01, attr02,attr03, create_date,last_update,creater, client_id)values (#item.status,jdbcType=VARCHAR,#item.assetClassifyId,jdbcType=BIGINT,#item.assetId,jdbcType=BIGINT, #item.assetItemId,jdbcType=BIGINT,#item.name,jdbcType=VARCHAR,#item.num,jdbcType=VARCHAR,#item.batchNum,jdbcType=VARCHAR, #item.tagId,jdbcType=VARCHAR,#item.rfid,jdbcType=VARCHAR, #item.epc,jdbcType=VARCHAR,#item.barcode,jdbcType=VARCHAR,#item.qrCode,jdbcType=VARCHAR,#item.erp,jdbcType=VARCHAR, #item.unit,jdbcType=VARCHAR,#item.picUrl,jdbcType=VARCHAR,#item.specification,jdbcType=VARCHAR,#item.model,jdbcType=VARCHAR,#item.material,jdbcType=VARCHAR,#item.color,jdbcType=VARCHAR, #item.length,jdbcType=DECIMAL,#item.width,jdbcType=DECIMAL, #item.height,jdbcType=DECIMAL,#item.weight,jdbcType=DECIMAL,#item.density,jdbcType=DECIMAL,#item.volume,jdbcType=DECIMAL, #item.price01,jdbcType=DECIMAL,#item.price02,jdbcType=DECIMAL,#item.warehouseId,jdbcType=BIGINT,#item.storageZoneId,jdbcType=BIGINT,#item.storageLocationId,jdbcType=BIGINT,#item.storageLocationTagId,jdbcType=BIGINT,#item.remark,jdbcType=VARCHAR, #item.attr01,jdbcType=VARCHAR,#item.attr02,jdbcType=VARCHAR,#item.attr03,jdbcType=VARCHAR,#item.createDate,jdbcType=TIMESTAMP,#item.lastUpdate,jdbcType=TIMESTAMP,#item.creater,jdbcType=BIGINT, #item.clientId,jdbcType=BIGINT)
以上是关于MyBatis中的几种注解映射的主要内容,如果未能解决你的问题,请参考以下文章
mybatis 批量增删改查操作的几种操作以及创建数据库索引