Some of the usual summaries

Source: Internet
Author: User

In MyBatis
#{} This value is compiled SQL statement and then value
${} This is a value to compile after the SQL statement


Bean and Map conversions
Import Java.lang.reflect.Field;
Import Java.lang.reflect.Modifier;
Import Java.util.HashMap;
Import Java.util.Map;
Import Java.util.logging.Logger;

/**
* @author ZWL
*
*/
public class Myconverutil {
private static Logger log = Logger.getlogger ("Myconverutil");

public static map<string, object> Po2map (Object o) throws exception{
map<string, object> map = new hashmap<string, object> ();
field[] fields = NULL;
String clzname = O.getclass (). Getsimplename ();
Log.info ("Class:" +o.getclass (). GetName ());
Fields = O.getclass (). Getdeclaredfields ();
Log.info ("* * *" +clzname+ "to map start * * * *");
for (Field field:fields) {
Field.setaccessible (TRUE);
String proname = Field.getname ();
Object provalue = Field.get (o);
Map.put (Proname.touppercase (), provalue);
Log.info ("Key:" +proname+ "value:" +provalue);
}
Log.info ("* * * *" +clzname+ "turn to map end * * * *");
return map;
}


public static Object Map2po (map<string,object> map,object o) throws exception{
if (!map.isempty ()) {
For (String K:map.keyset ()) {
Object v = "";
if (!k.isempty ()) {
v = map.get (k);
}
field[] fields = NULL;
Fields = O.getclass (). Getdeclaredfields ();
String clzname = O.getclass (). Getsimplename ();
Log.info ("Class:" +o.getclass (). GetName ());
Log.info ("***map turn" +clzname+ "Start * * * *");
for (Field field:fields) {
int mod = Field.getmodifiers ();
if (modifier.isstatic (mod) | | Modifier.isfinal (MoD)) {
Continue
}
if (Field.getname (). toUpperCase (). Equals (k)) {
Field.setaccessible (TRUE);
Field.set (o, v);
Log.info ("Key:" +k+ "value:" +v);
}

}
Log.info ("***map turn" +clzname+ "End");
}
}
return o;
}
}

SQL Date format Query
http://linkyou.blog.51cto.com/1332494/751980/

#按照月查询
SELECT date_format (CDATE, '%y%m ') months,applyrate, Date_format (MAX (CDATE), '%y-%m-%d%h:%i:%s ') CDATE from Care_ Customer_log C
GROUP by months
ORDER by C. ' CDATE ' DESC;
#按照天查询
SELECT date_format (CDATE, '%y%m%d ') days,applyrate, Date_format (MAX (CDATE), '%y-%m-%d%h:%i:%s ') CDATE from Care_ Customer_log C
GROUP by Days
ORDER by C. ' CDATE ' DESC;





synchronized :
The Java keyword, used to decorate a method or block of code, ensures that at most one thread executes the code at the same time.
One, when two threads concurrently access the synchronized (this) synchronization code block in the same object, only one process can be executed within a single time. The other
must wait for the current thread to finish executing the code block before it can execute the code block.
Two, When a thread accesses the synchronized (this) of object to synchronize the code block, Another thread can access the object's non-synchronized (this) synchronization code block.
Three, when a thread accesses the synchronized (this) of object to synchronize the code block , other threads to object all other synchronized (This) Access to the synchronization code block is blocked.
Four, when a When a thread accesses the synchronized (this) of object to synchronize a block of code, acquires the object lock for this object. As a result, all of the synchronization code block accesses to the object by other threads are temporarily blocked.
Five, normal code than synchronous code first execution
Code:
Example 1:

public class Thread1 implements Runnable {
public void Run () {
Synchronized (this) {
for (int i = 0; i < 5; i++) {
System.out.println (Thread.CurrentThread (). GetName () + "= = =" + i);
}
}
}
public static void Main (string[] args) {
Thread1 T1 = new Thread1 ();
Thread ta = new Thread (T1, "A");
Thread TB = new Thread (T1, "B");
Ta.start ();
Tb.start ();
}
}

Synchronized method: Declare the Synchronized method with the Synchronized keyword:

Example: public synchronized void syntest (int newval);

Mainly used to control the access of class member variables, each instance of the class corresponds to a lock, however, the method must be called before calling an instance lock of the class to access, otherwise the thread will block, once the method is executed, the lock of the class of the method is locked, knowing that the method executes or returns the result before releasing the lock.

 Vector keyword:

  Vectors can be used to achieve an automatically growing array of objects.

vector class provides Three kinds of tectonic methods: &NBSP;

Using the first method, the system automatically manages the vectors, if the latter two methods are used. The system will initialcapacity the capacity of the vector object according to the parameters (that is, the vector object can store the size of the data), when the number of data actually stored exceeds the capacity. The system expands the vector object storage capacity.

The parameter capacityincrement is given an expanded value for each expansion. When the capacityincrement is 0, it is no longer expanded by one time, and this function optimizes storage. A variety of methods are available in the vector class for user-friendly use:

Insert Function:
(1) Public final synchronized void adddelement (Object obj)
Inserts obj at the tail of the vector. Obj can be any type of object. Objects of different classes can also be inserted into the same vector object. But instead of a numeric value, you should be careful to convert the array to the appropriate object when inserting values.
For example: To insert an integer 1 o'clock, do not call V1.addelement (1) directly, the correct method is:
Vector v1 = new vector ();
Integer integer1 = new Integer (1);
V1.addelement (Integer1);
(2) Public final synchronized void Setelementat (Object obj,int index)
The object at index is set to obj, and the original object is overwritten.
(3) Public final synchronized void Insertelement (Object obj,int index)
Inserts obj at the position specified by index, and the original object and subsequent objects are deferred sequentially.

Remove Features:
(1) Public final synchronized void removeelement (Object obj)
Remove obj from the vector, and if there are multiple, try starting from the vector header and delete the first vector member found with the same obj.
(2) Public final synchronized void Removeallelement ();
Delete all objects of vector
(3) Public fianl synchronized void removeelementat (int index)
Delete an object where Index refers to

Query search function:
(1) Public final int indexOf (Object obj)
Searches for obj from the vector header, returns the subscript corresponding to the first obj encountered, and returns 1 if the obj does not exist.
(2) public final synchronized int indexOf (Object obj,int index)
Search for obj starting at the subscript indicated by index.
(3) Public final int lastindexOf (Object obj)
Reverses the search for obj from the tail of the vector.
(4) Public final synchornized int LastIndex (Object obj,int index)
The inverse of the tail-to-head search from the subscript at index indicates obj.
(5 ) Public final synchornized firstelement ()  
of a vector object




Some of the usual summaries

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.