From d6918e1f9e1784a89a53730a59b251d88b31532b Mon Sep 17 00:00:00 2001
From: Anatolii Stepaniuk
If the environment is omitted, then the default environment is
loaded, as follows:
From 58d46df30bd356f3b4a6e008f60d038fa6705cab Mon Sep 17 00:00:00 2001
From: Anatolii Stepaniuk
The environments element defines how the environment is
configured.
@@ -1841,8 +1841,8 @@ public class C3P0DataSourceFactory extends UnpooledDataSourceFactory {
MyBatis is able to execute different statements depending on your database vendor.
The multi-db vendor support is based on the mapped statements databaseId attribute.
MyBatis will load all statements with no databaseId attribute
- or with a databaseId that matches the current one. If case the same statement
- if found with and without the databaseId the latter will be discarded.
+ or with a databaseId that matches the current one. In case the same statement
+ is found with and without the databaseId the latter will be discarded.
To enable the multi vendor support add a databaseIdProvider
to mybatis-config.xml file as follows:
file:/// URLs), class names or package names.
For example:
From 4678bb093725272123428c17fb73947aac86b58e Mon Sep 17 00:00:00 2001
From: Anatolii Stepaniuk In all of the past statements, you've seen examples of simple parameters. Parameters are very powerful elements in MyBatis. For simple situations, probably 90% of the cases, there's not much - too them, for example: + to them, for example:
The example above demonstrates a very simple named parameter mapping. The parameterType is set to
- int, so therefore the parameter could be named anything. Primitive or simply data types such as
+ int, so therefore the parameter could be named anything. Primitive or simple data types such as
Integer and String have no relevant properties, and thus will replace the full value of the
parameter entirely. However, if you pass in a complex object, then the behavior is a little
different. For example:
@@ -643,8 +643,8 @@ ps.setInt(1,id);]]>
By default, using the #{} syntax will cause MyBatis to generate PreparedStatement properties and
set the values safely against the PreparedStatement parameters (e.g. ?). While this is safer,
- faster and almost always preferred, sometimes you just want to directly inject a string
- unmodified into the SQL Statement. For example, for ORDER BY, you might use something like this:
+ faster and almost always preferred, sometimes you just want to directly inject an unmodified string
+ into the SQL Statement. For example, for ORDER BY, you might use something like this:
- And remember that TypeAliases are your friend. Use them so that you don't have to keep typing the + And remember that TypeAliases are your friends. Use them so that you don't have to keep typing the fully qualified path of your class out. For example:
@@ -787,7 +787,7 @@ public class User { ]]>- Now if only the world were always that simple. + Now if only the world was always that simple.
- These are the most basic of result mappings. Both id, and + These are the most basic of result mappings. Both id and result map a single column value to a single property or field of a simple data type (String, int, double, Date, etc.).
From 9e442180aad9177bffd3b78db7aa1c4b9827d01e Mon Sep 17 00:00:00 2001 From: Anatolii Stepaniuk- As we did for the association, we can call an stored procedure that executes two queries and returns two result sets, one with Blogs + As we did for the association, we can call a stored procedure that executes two queries and returns two result sets, one with Blogs and another with Posts:
From e29c5de20851fd0bb932ec47bd2a9c72bf611688 Mon Sep 17 00:00:00 2001 From: Anatolii StepaniukNow you have a SqlSessionFactory that can be used to create SqlSession instances.
SqlSessionFactory has six methods that are used to create SqlSessionInstances. In general, the decisions you'll be making when selecting one of these methods are:
+SqlSessionFactory has six methods that are used to create SqlSession instances. In general, the decisions you'll be making when selecting one of these methods are:
While the various insert, update, delete and select methods above are powerful, they are also very verbose, not type safe and not as helpful to your IDE or unit tests as they could be. We've already seen an example of using Mappers in the Getting Started section above.
Therefore, a more common way to execute mapped statements is to use Mapper classes. A mapper class is simply an interface with method definitions that match up against the SqlSession methods. The following example class demonstrates some method signatures and how they map to the SqlSession.
In a nutshell, each Mapper method signature should match that of the SqlSession method that it's associated to, but without the String parameter ID. Instead, the method name must match the mapped statement ID.
@@ -574,7 +574,7 @@ User getUserById(Integer id); @Select("select * from company where id = #{id}") Company getCompanyById(Integer id); -This example shows solo parameter using the Sql Provider annotation:
+This example shows solo parameter using the SelectProvider annotation:
MyBatis 3 offers a convenient utility class to help with the problem. - With the SQL class, you simply create an instance lets you call methods against it to build a SQL statement + With the SQL class, you simply create an instance that lets you call methods against it to build a SQL statement one step at a time. The example problem above would look like this when rewritten with the SQL class: