The domain model is written according to the business logic, and the generated object (object security, detached from the data layer) processes the business logic, written according to the business logic, and if each class corresponds to a data table it is best to do so, but real production is not. The main function is this, such as the bus station will have a lot of buses (bus is also an object, it may have passengers) and the basic information of the station (name, etc.), we declared the stati
Mapper interface development method only requires programmers to write the Mapper interface (equivalent to Dao interface), the MyBatis framework creates an interface based on the interface definition of the dynamic proxy object, the proxy object's method body with the upper Dao Interface Implementation class method. Mapper interface Development is subject to the
List of properties for mapperDEFAULTHANDLER Specifies the default processor (the processor is the Controller (action) class that you define) in cases where the mapping does not match all processorsOrder Spring sorts the mapper based on the value of the order and uses the first matching processor, the smaller the order value, the higher the priority (equivalent to the index position of the chain, starting at 0, and level 0 highest)List of interceptors
In the article "Simple MyBatis Series (vi)---objectfactory, plugins, Mappers Introduction and Configuration" Simply put a full stop to the MyBatis configuration. So from the beginning of this article, will introduce the mapper mapping file configuration, this is one of the core of MyBatis, must learn. In the mapper file, with mapper as the root node, the followin
# #Example Example = new # #Example ();
Example.setorderbyclause ("field name ASC");//in ascending order, desc in descending order.
Example.setdistinct (false)//Remove Duplicates, Boolean, True to select records that are not duplicates.
Criteria = new Example (). Createcriteria ();
is null;is not null;
Equal to (value); n equal to (value);
GreaterThan (value); Greaterthanorequalto (value);
LessThan (value); Lessthanorequalto (value);
In (Item,item,item,...); Not in (
example) THORWS SQLException: Query List by CriteriaSelectbyexamplewithblogs (userexample example) THORWS SQLException: Query by criteria (including BLOB fields). Only if the field type in the data table is binary is it generated. intUpdatebyprimarykey (User record) Thorws SQLException: Update by primary keyintupdatebyprimarykeyselective (User record) Thorws SQLException: Update A field with a value that is not NULL by the primary keyintupdatebyexample (User record, userexample example) THOR
Configuring log4j is relatively straightforward, such as logging of this mapper interface needs to be logged:Package Org.mybatis.example;public interface Blogmapper {@Select ("select * FROM blog WHERE id = #{id}") Blog Selectblog (int id);}As long as a file named log4j.properties is created in the app's classpath, the specific contents of the file are as follows:# Global Logging Configurationlog4j.rootlogger=error, stdout# MyBatis logging configuratio
Development specification:Mapper interface development method only need to program ape to write Mapper interface (equivalent to DAO interface),Dynamic proxy objects that are created by the MyBatis framework based on the interface definition.The method body of the proxy object is the same as the DAO interface implementation class method.Mapper interface development is subject to the following specifications:The namespace in the 1.mapper.xml file is the
Original address
Although MyBatis is very convenient, but want to write all the mapper still very tiring, fortunately mybatis the official introduction of automation tools, can be based on the database and the definition of a good configuration directly generated DAO layer and all the following code, very convenient.First WOM We build a maven project, I don't write it in detail here.Mybatis-generator Use configuration
Open the Pom.xml file and add 3
Device Mapper learning in Linux, devicemapper
In linux, when you use some commands (such as nmon and iostat), you may see some devices named dm-xx. What exactly are these devices, what is the relationship with the disk? I was wondering when I didn't know it before. in fact, dm is the abbreviation of Device Mapper. Device Mapper is a ing Framework mechanism provid
MyBatis General-Purpose Mapper General example use, of course, there is no general mapper common example use
Want to lazy not write a lot of mybatis in the Mapper.xml file, you want to use the generic mapper class to reduce the workload.
First, I'm using a MAVEN project, so importing Mapper's maven dependency
[HTML] view plain copy
There is also a necessary depe
1. The configuration of the front controller Dispatcherservlet is configured in Web. XML to be the same as the servlet configuration1) contextconfiglocation configuration Sprimgmvc loaded configuration file (Configuration Processor mapper, adapter, etc.) if Contextconfiglocation is not configured, the default load is/web-inf/ Servlet name-servlet.xml (springmvc-servlet.xml)2)The first type: *.action, accessed with. Action ends resolved by Dispatcherse
1. Configure the note Mapper and adapter. -- Bean class="Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" /> -- Bean class="Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />However, in the actual development, the annotations of the adapter and mapper configuration is often used to note-driven:
Using Mvc:annotation-driven in
Mrunit can take less time and can test mapper and reducer separatelySteps:1, the use of Mrunit test mapper and Reducer2, the implementation of the MapReduce code localization test3. Using Hadoop logs4. Track execution metrics by counterThe process of testing mapper1, instantiate the Mapdirver class, as the test mapper is parameterized2. Call the Withmapper method
First, note: version issuesspring3.2 Previous versions, the annotated mapper and adapter used the following two classes.Org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping. class Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter. classIn the new version of the source code, you can see the following comments:The following classes are used in the 3.2 included and later versions:Org.springframework.w
Prerequisites: already integrated MyBatisCode generation steps:
Add dependencyDependency> groupId>Tk.mybatisgroupId> Artifactid>Mapper-spring-boot-starterArtifactid> version>1.1.4version>Dependency>Dependency> groupId>Org.mybatis.generatorgroupId> Artifactid>Mybatis-generator-coreArtifactid> version>1.3.6version>Dependency>
Create a class with the main method, the code is as follows PackageCom.ghaien.generator;ImportOrg.mybatis
PrefaceMyBatisAbout MyBatis, most people are familiar with it. MyBatis is an excellent persistence layer framework that supports custom SQL, stored procedures, and advanced mapping. MyBatis avoids almost all JDBC code and manually sets parameters and gets the result set. MyBatis can use simple XML or annotations to configure and map native information, mapping interfaces and Java POJOs (Plain old Java Objects, ordinary Java objects) to records in a database.Whether DDD (domain driven Design, dom
*########################################### * @author Zhuxy * @time 2016-3-13 10:21:06 29 * 30 To public class Modulemapreduce extends configured implements Tool {/** * Mapper class 35 *
/The public static class Modulemapper extends MapperView Module Code
Template usage Steps:
1) Change name (MapReduce class name, Mapper class name, reducer class name)
2) Modify the type of key/value input and output par
I. Principles of MAPPER Agent developmentRequires the namespace attribute value in the mapper mapping file, which must be the fully qualified name of the Mapper proxy interfaceRequires a declaration of the SQL statement label in the Mapper mapping file, consistent with the declaration of the
the XML definition. 1, create a new Com.kang.mapper package, define the map interface, interface name arbitrary, here is usermapper.
Package com.kang.mapper;
Import java.util.List;
Import Com.kang.pojo.User;
Public interface Usermapper {
//query user information based on User ID public username
finduserbyid (int id) throws Exception;
Query user list public
list2. Configuring the XML file Usermapper.xml
Note that the id attribute value in the configuration file
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.