This is the 28th day of my participation in the August Text Challenge.More challenges in August

ORM

  • ORM is a mapping model between database tables and simple Java objects
  • The main solution is the mutual mapping of database data and POJO objects
    • Through this layer of mapping, you can easily and quickly transform the data of jiang database tables into POJOs

Mybatis

  • It mainly consists of three parts
    1. SQL
    2. Mapping rules
    3. POJPO

  • We map the method name in the interface to the ID in the XML file
public interface StuMapper {
    public Stu getStu(Long id);
}
Copy the code
<select id="getStu" parameterType="long">
    select
        id,name,adress,role,age
    from stu
    where id = #{id}
    limit 10
</select>
Copy the code
  • Where parameterType indicates that we are passing a java.lang.Long type parameter to this SQL
    • And the return is resultType is the data type that we need to return

Common elements of Mybatis

– cache – Cache configuration of the namespace.

  • Cache-ref – References the cache configuration of other namespaces.
  • ResultMap – describes how to load objects from a database result set, and is the most complex and powerful element.
  • SQL – reusable block of statements that can be referenced by other statements.
  • Insert – Mapping insert statements.
  • Update – Mapping update statement.
  • Delete – Mapping delete statement.
  • Select – Mapping query statement.
<insert id="insertAuthor">
insert into Author (id,username,password,email,bio)
values (#{id},#{username},#{password},#{email},#{bio})
</insert>
 
<update id="updateAuthor">
update Author set
username = #{username},
password = #{password},
email = #{email},
bio = #{bio}
where id = #{id}
</update>
 
<delete id="deleteAuthor">
delete from Author where id = #{id}
</delete>
Copy the code

The most common scenario for if to use dynamic SQL is to include part of a WHERE clause based on criteria

Choose use – When we use one of many conditions, use choose – similar to the swich statement we use

Set keyword (fixes the above two defects)

foreach

In fact, when we often write habits, so these are familiar with the heart 🤪