Project Miscellaneous

1. The amount in java needs to be separated by commas, java has its own API, java.text.NumberFormat

NumberFormat nf = NumberFormat.getInstance();

nf.format ();

 

2. Java sorts the objects in a list using Collections.sort. Among them, if A is greater than B, return 1, it is ascending order; if A is greater than B, return -1, it is descending order

 

3. To determine whether a string is a number in java, you can use the StringUtils.isNumeric() method. However, this method cannot test for numbers with a minus sign "-", and empty strings are also considered numbers.

StringUtils.isNumeric(null)   = false
StringUtils.isNumeric("")     = true
StringUtils.isNumeric("  ")   = false
StringUtils.isNumeric("123")  = true
StringUtils.isNumeric("12 3") = false
StringUtils.isNumeric("ab2c") = false
StringUtils.isNumeric("12-3") = false
StringUtils.isNumeric("12.3") = false

 

Of course, using regular expressions is the most flexible approach

String regex = "[0-9]*";

 

4. TreeMap implements custom comparator in java

Map<String, Object> pageMap = Maps.newTreeMap(new Comparator<String>() {
	@Override
	public int compare(String o1, String o2) {
		if (StringUtils.isNumeric(o1) && StringUtils.isNumeric(o2)) {
			if (Integer.parseInt(o1) > Integer.parseInt(o2)) {
				return 1;
			}
		}
		return -1;
	}
});

 

5. Too many databases are used, which can easily lead to confusion of database functions. Remember the null handler function.

MySql中 IFNULL(expr1,expr2)

Returns expr1 if expr1 is not NULL, otherwise returns expr2.

MySql中 IF(expr1,expr2,expr3)

If expr1 is TRUE (expr1<>0 and expr1<>NULL), then it returns expr2, otherwise it returns expr3

 

6. When the project log runs normally locally, and there is a problem with sending it to the linux environment, you need to deal with the problem from the aspects of permissions, paths, and jar conflicts.

 

7. If it is encountered in the project, it will report an error that a certain class cannot be found at startup, but the program has no compilation exception, and the class can also be found in the project. So what is the problem, it is basically caused by the conflict of the jar package.

 

8. For the web app libraries in the web project, this configuration can be submitted to the version control server, and other members can check it out. If you need to add a jar package to it, you can go to the package explorer, find it under web-inf/lib, and then add or delete it.

 

9. mybatis generator and or joint query

UserExample example = new UserExample();  
UserExample.Criteria criteria = example.createCriteria();  
criteria.andIdEqualTo (mctid);  
criteria.andStatusEqualTo("0");  
          
UserExample.Criteria criteria2 = example.createCriteria();  
criteria2.andIdEqualTo (mctid);  
criteria2.andLaststatusEqualTo("0");  
example.or(criteria2);  
UserDao.countByExample(example);
Generated sql statement:
select count(*) from USER WHERE ( TOID = ? and STATUS = ? ) or
( ID = ? and LASTSTATUS = ? )  

 

10. Use Firefox's RestClient plugin to make a Post request. At this time, you need to configure the Content-Type on the headers tab as application/x-www-form-urlencoded;charset=UTF-8

 

11.mysql database query hexadecimal field

SELECT inet_ntoa (conv (hex (location_ip), 16, 10)) as ip,

conv(hex(idvisitor), 16, 10) as visitorId FROM piwik_log_visit;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326442321&siteId=291194637