Details of basic example of mybatis

  • 2020-06-15 08:35:19
  • OfStack

Without further ado, I would like to share the basic example code of mybatis, as shown below:


<configuration>
  <properties resource="db.properties">
    <property name="" value=""/>
  </properties>
  <!--  names  -->
  <typeAliases>
     <package name="com.my.mybatis.beans"/> <!--  An alias for : The name of the class  -->
     <package name="com.my.mybatis.xml"/>
    <!--
    <typeAlias type="com.my.mybatis.xml.User" alias="_User"/>
    -->
  </typeAliases>
  <environments default="development">
    <environment id="development">
      <transactionManager type="JDBC" />
      <dataSource type="POOLED">
        <property name="driver" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/mybatis" />
        <property name="username" value="root" />
        <property name="password" value="tiger" />
      </dataSource>
    </environment>
  </environments>
  <mappers>
    <mapper resource="com/my/mybatis/userMapper.xml"></mapper>
    <mapper resource="com/my/mybatis/xml/testUserXml.xml"/>
    <mapper class="com.my.mybatis.xml.UserMapper"/>
    <mapper resource="com/my/mybatis/one2one/one2one.xml"/>
    <mapper resource="com/my/mybatis/one2many/one2many.xml"/>
    <mapper resource="com/my/mybatis/jstllike/jstl.xml"/>
    <mapper resource="com/my/mybatis/procedure/store.xml"/>
  </mappers>
</configuration>

Take a look at the mybatis free fuzzy query


<select id="getlike" parameterType="ConditionUser" resultType="User">
    select * from d_user where 
    <if test="name != null">
    <!--  The following format  -->
    name like '%' #{name} '%' and 
    </if>
    age between #{minAge} and #{maxAge}
  </select>

Well, that's the end of the code, and I hope it helps.


Related articles: