首页 > 其他 > 详细

mybatis记录

时间:2017-10-17 22:12:05      阅读:179      评论:0      收藏:0      [点我收藏+]
    <insert id="insertTeacherGroup">
        INSERT INTO
        grouplink(TEACHER_ID,CLASS1_ID) VALUES (#{teacherId},#{class1Id})
    </insert>

如果有多个参数,未使用BO,需要在dao层加 @Param(对于的配置文件中的占位符)

 

public void insertTeacherGroup(@Param("teacherId")Integer teacherId, @Param("class1Id") Integer class1Id);

 

 

2、使用MyBatis往数据库中插入一条记录后,需要返回该条记录的自增主键值。

需要添加 useGeneratedKeys="true" keyProperty="id"

<insert id="insertTeacher" parameterType="Teacher"  useGeneratedKeys="true"  keyProperty="id">
        INSERT INTO
        teacher(TEACHER_NAME) VALUES (#{teacherName})
    </insert>

 

3、当查询一对多(例子:bo 中List<Class1> classes)情况下 使用<collection>标签书写。

<resultMap type="Teacher" id="teachersResult">
        <id property="id" column="ID" />
        <result property="teacherName" column="TEACHER_NAME" />
        <collection property="classes" ofType="Class1">
            <result property="class1Name" column="CLASS1_NAME" />
        </collection>
    </resultMap>

 

mybatis记录

原文:http://www.cnblogs.com/hufeng1989/p/7684253.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!