1
General Mapper1.1
General Mapper Introduction 1.1.1
Architecture Design
Note : after the use of universal Mapper , the Single-table additions and deletions to the operation will be automatically maintained .
question : How can you achieve universal and Dynamic Data ?
1.2
JPA Introduction 1.2.1
The idea of JPA
Description : manipulate database with object-oriented thinking !!
To illustrate :
- early SQL statements require human editing .
- The data table in the relational database corresponds to pojo one by one . so you can manipulate the database with objects
- Sql:insert into user values (XXXX);
Usermapper.insert (user);
1.2.2
J
PA
of development
description : with JPA thought , haibernate will implement JPA .
features :
- Ability to implement object-oriented operations
- ability to implement automatic object-relational mapping (ORM)
Questions :
Example :
If you do an insert operation , the query operation is performed before It is inserted .
when implementing business logic , a large number of redundant SQL statements are generated . database execution slows down .
2. need to learn specific database statements HQL (for multi-table operations)
Development :
the development of Mybatis.
features :
- Ability to implement automatic object-relational mapping
- SQL statements need to be self-fulfilling according to business logic , with higher performance
- General after the advent of Mapper , Mybatis also has an object-oriented function .
1.2.3
Universal Mapper Introduction
<!--Universal Mapper Plug-in - <pluginInterceptor= "Com.github.abel533.mapperhelper.MapperInterceptor"> <!--primary key self-increment write method, default value MySQL, detailed description please see the document - < Propertyname= "IDENTITY"value= "MYSQL" /> <!--Universal Mapper interface with multiple universal interfaces separated by commas - < Propertyname= "Mappers"value= "Com.jt.common.mapper.SysMapper" /> </plugin>
1.2.4
Annotated form of the Mapper interface
/** * MyBatis interface can be added annotations, complete specific actions * Description: * MyBatis directly according to the mapping label developed later. * functionally consistent with the mapping file. @return */ @Select (Value= "SELECT * from Item") //@Insert ("") // @Delete ("") // @Update ("") List<item> SelectAll ();
1.2.5
General Mapper call rules
The method name is corresponding and can be called automatically
1.3
new additions to the product1.3.1
series of commodity classifications
Description : General e-commerce website Commodity classification is generally 3. after a scientific research .
1.3.2
build Item
Cat
Object
1.3.3
build Item
Cat
Mapper
1.3.4
define Item
Catservice
@Service Public classItemcatserviceimplImplementsItemcatservice {@AutowiredPrivateItemcatmapper Itemcatmapper; /*** Using Universal Mapper (JPA), the incoming object eventually serves as the where condition of the query * select * FROM tb_item_cat WHERE id = 1 * * Summary: The Itemcat object will act as a where condition for a non-nullable property */If you need to add a query condition * Assign a value to an object's properties!!! * */@Override PublicList<itemcat>Finditemcat () {//itemcat itemcat = new Itemcat (); //Itemcat.setid (100L); //itemcat.setstatus (1); returnItemcatmapper.select (NULL); }
1.3.5
Edit Item
Catcontroller
1.4
implementation of commodity classification list1.4.1
of the page
URL
Analysis
1.4.2
Analyze tree structure
{"id": 2, "text": " trade name ", State: "Closed"}
Note : If the property of state is closed, it indicates that this is a parent node and that it has child nodes. Open represents a child node
1.4.3
Expansion Node
1.4.4
Edit Pojo object
Description : Edit the get method According to the format requirements :
1.4.5
Edit Controller
/*** [email protected] * Function: * If the returned data when the object is automatically converted to Json{key:value} * If the returned data is a string then return as the string Back String * Note: When converting JSON data, the GETXXX () method in the object is called *@return */ //Product Classification Implementation@RequestMapping ("/list") @ResponseBody PublicList<itemcat>Finditemcat (@RequestParam (Value= "id", defaultvalue= "0") Long parentid) {//Long parentid = 0L; //define the parent of a first-level menu//according to the ParentID query the product classification information returnItemcatservice.finditemcatbyparentid (ParentID); }
1.4.6
Edit Service
@Override Public List<itemcat> Finditemcatbyparentid (Long parentid) { new itemcat (); Itemcat.setparentid (parentid); Itemcat.setstatus (// normal classified information return itemcatmapper.select (itemcat ); }
1.4.7
Effect Show
1.5
new additions to the product1.5.1
Analysis page ur
L
1.5.2
Edit
Pojo
Object
Description : the pojo object corresponds to database table one by one
1.5.3
Edit
Controller
1.5.4
Edit Service
1.5.5
Effect Show
1.5.6
Easy
UI
the checksum
- Required Fields
Data-options= "Required:true"
- Set the range of values
Data-options= "Min:1,max:99999999,precision:2,required:true"
- Define the number of characters
data-options= "Validtype: ' length[1,30] '
1.6
Modification of goods1.6.1
page js analysis
1.6.2
Edit Controller
//Introducing the Logging tool class Private Static FinalLogger Logger= Logger.getlogger (Itemcontroller.class); @RequestMapping ("/update") @ResponseBody Publicsysresult UpdateItem (item item) {Try{Itemservice.updateitem (item); Logger.info ("{~~~~~ update succeeded}"); returnSysresult.build (200, "Update succeeded"); } Catch(Exception e) {e.printstacktrace (); //throw new Exception (); //Record Log//System.out.println ("Sssssss");Logger.error ("{Update operation failed}"); returnSysresult.build (201, "Update Failed"); } }
1.6.3
Edit Service
1.6.4
Dynamic Update operations ( Knowledge Review )
< dynamic Update set function for!--test:1. Dynamic update using 2. The extra 1 commas before the where condition can be removed -- <update id= "UpdateUser" > update tb_user = #{name} age=#{age} where id = #{id} <set> <if test= "Name!=null" >name = #{name},</if> <if test= "Age !=null" >age = #{age},</if> </set> = #{id} </update>
1.7
Product Deletion1.7.1
Page Analysis
1.7.2
Edit Controller
1.7.3
Edit Service
1.8
merchandise shelves under the shelf1.8.1
page analysis for shelves and racks
1.8.2
Edit Controller
1.8.3
Edit service
@Override public void updatestatus (int status, Long[] (IDs) { /** * Scenario 1: * Operation in the service layer via loop traversal * Scenario 2: * Implementation of bulk modification of data by MyBatis */ Itemmapper.updatestatus (status,ids); /* for (Long id:ids) {Item item = new Item (); Item.setid (ID); Package primary key Item.setstatus (status); item.setupdated (New Date ()); Itemmapper.updatebyprimarykeyselective (item); */ }
1.8.4
Edit Mybatis
<!--Batch modification status collection values are like the following 1. If the data passed is array 2. If the data passed is a list collection of List 3. If the data passed is a key in the map map - <UpdateID= "UpdateStatus">update Tb_item Set status = #{status} where ID in (<foreachCollection= "IDs"Item= "id"Separator=",">#{id}</foreach> )
</update>
1.9
Log
4j
Log1.9.1
Description :
- The project can automatically scan the \resources\log4j.properties. name must be fixed .
- Introducing jar package Files
2
Supplemental Knowledge2.1
Quick Configuration
Description : the ability to appear in new java such as class interface The tool class
2.1.1
jQuery Validate
Universal Mapper and classification implementation