一聚教程网:一个值得你收藏的教程网站

mybatis基本实例详解

时间:2017-08-03 00:00:00 编辑:简简单单 来源:转载

废话不多说了,先给大家分享mybatis基本实例代码,具体代码如下所示:

 代码如下

<configuration>

  <properties resource="db.properties">

    <property name=""value=""/>

  </properties>

  <!-- 起别名 -->

  <typeAliases>

     <packagename="com.my.mybatis.beans"/> <!-- 别名为:类名 -->

     <packagename="com.my.mybatis.xml"/>

    <!--

    <typeAlias type="com.my.mybatis.xml.User"alias="_User"/>

    -->

  </typeAliases>

  <environmentsdefault="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"/>

    <mapperclass="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>

下面看下mybatis 自由模糊查询

 代码如下

<select id="getlike"parameterType="ConditionUser"resultType="User">

    select * from d_user where

    <iftest="name != null">

    <!-- 如下格式 -->

    name like'%'#{name}'%'and

    </if>

    age between #{minAge} and #{maxAge}

  </select>


文章评论

热门栏目