Knowledge daily summary records 54

mybatis in the same transaction, executing the same loop sql statement, only the first issue will be executed ( source )

I. Description of the problem:

When using spring @Transaction affairs, in a for loop needs to execute the same query multiple times, after the first check out the object, the object to be modified, then when the results of the second query, the query returns data on their own a modified data. Because the business needs to take every query needs to change the database, modify the value after the first cycle of operation will be based on future queries.

Second, the solution:
Add flushCache = "true" in the xml file select statement, told mybatis flush the cache after the end of the query, the query results are not recorded into a cache

<select id="pageListCount" resultType="int" flushCache="true">

Three reasons:

mybatis There cache and secondary cache, mybatis statement of the query cache will exist, if in a transaction, mybatis multiple queries on the same session with a sql statement will look for the cache rather than go check again database

Alternatively Mysql use in outer and Not in connection ( source )

select * from table t where t.id not in (select id from table2)
-->
select a.* from table1 a left join table2 b on a.id = b.id where b.id is null; 
-->
select a.* from table1 a left join table2 b on a.id = b.id where b.id is not null; 

String.format () string ( source )

String.format () two overloaded ways to format string conventional type of
format (String format, Object ... args ) new string using the local language environment, develop new string parameter string format and generate formatted.
format (Locale locale, String format, Object ... args) using the specified locale, format string and string to develop parameters to generate formatted.

Detailed Description Example conversion specifier
% s string type "like please bookmark"
% C character type 'm'
% B Boolean to true
% integer type D (decimal) 88
% integer type X (hexadecimal) the FF
% O integer type (octal) 77
% floating type F 8.888
% hex a floating type FF.35AE
% e + index type. 5 9.38e
% G general floating point type (f and e of the shorter type) example without (substantially less than)
% H example hash codes do not (substantially less than)
%%% type percentage (% %% to display special characters%)
(substantially less than) line breaks example n-%
% TX date and time type (x represents a different date and time conversion operator) Examples not (substantially less than)

Advanced Features:
Flag Description Example Result

  • Is a positive or negative sign is added ( "% D +", 15) +15
    0 0 fill before the number (encryption used) ( "% 04d", 99 ) 0099
    blank spaces added before the specified number of the integer ( "% 4d" , 99) 99
    , to "," digital packet (conventional amount shown) ( "%, F", 9999.99) 9,999.990000
    (including negatives parentheses ( "% (F ', -99.99) (99.990000)
    # If a float contains decimal, hexadecimal, or if the octal 0x is added or 0 ( "% X #", 99) ( "% # O", 99) 0143 0x63
    <a conversion specifier before formatting parameters as described ( "% f and% <3.2f", 99.45) 99.450000 and 99.45

In the first example there comes% tx x represents the date conversion specifier way I include the date conversion specifier

Flag Description Example
c Saturday Shiyue 27 14:21:20 CST 2007 including all date and time information
F "year - month - day" format 2007-10-27
D "month / day / year" format 10/27/07
r "HH: MM: SS PM" format (12 hour) 02:25:51 pm
T "HH: MM: SS" format (24) was 14:28:16
R & lt "HH: the MM" format (24-hour format ) 14:28

Multipartfile and File Type conversion

With this package classes org.apache.commons.io

1.M转F

File file = new File(path); 

FileUtils.copyInputStreamToFile(multipartFile.getInputStream(), file);  

2.F转M

File file = new File("src/test/resources/input.txt");

FileInputStream input = new FileInputStream(file);

MultipartFile multipartFile =new MockMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(input));

StringBuffer related operations ( source )

The principle by strings implemented by the class.
StringBuffer can add, delete the contents of the string.
StringBuffer is a container. A string buffer.
Many ways the same as the String.
StringBuffer is a variable length.

Containers features:
variable-length, can operate a plurality of types, can be converted to the final string by toString ().

storage.
StringBuffer append (): Specifies the type of data added to the end of existing data type as a parameter.
StringDuffer insert (index, data): index data may be inserted into position.

delete.
StringBuffer delete (start, end): Delete data buffer, including start, does not contain the end.
StringBuffer deleteCharAt (index): delete the character at the specified location.

获取。
char charAt( int index )
int indexOf( String str )
int lastIndexOf( String str)
int length( )
String substring(int start, int end)

修改。
StringBuffer replace(int start, int end)
void setCharAt(int index, char ch)

Reverse.
StringBuffer reverse ();

The data stored in the specified buffer to the specified character array.
void getChars (int srcBegin, int srcEnd , char [] dst, int dstBegin)

Guess you like

Origin www.cnblogs.com/cuiyf/p/12048377.html