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
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
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
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
This article immediately follows the job flow: the factors that determine the number of maps ,after the job submission is completed, is handled by the Mapper class. 1). The setup () and Cleanup () two methods in the Mapper class are responsible for the initialization and cleanup of the map task ( default is an empty implementation )2). The Run () method in the Mapper
In the actual application, there will be more mapper. If each new mapper is added, it will be inconvenient to add the corresponding configuration file to the Sqlmapconfig.You can create a new package, place Mapper.java underneath it, and place the same named Mapper.xml under it.In this way, you can use Be aware of the. Java and. XML naming, and Mapper.xml namespace.First,
Following the previous example project Http://www.cnblogs.com/EasonJim/p/7083165.html, using the Configdecoratormapper Mapper, the page under the specified directory is the same as the template page.On the use, just set two places, no configuration on the basic page.1, Decorators.xmlXML version= "1.0" encoding= "UTF-8"?>DecoratorsDefaultDir= "/decorators"> Decoratorname= "Basic-theme"page= "basic-theme.jsp"> Decorator>Decorators>2, Sitem
Because DAO development, will create entity class object every time, will pass in fixed query value such as ID, there is hard coding problem, so adopt mapper dynamic proxy (do not create entity class object, need interface only, automatically generate by mapper) as before MyBatis (a) step, However, you need to make changes to the Mapper.xml file:Namespace: must be the full path of the interface class (ID: M
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.