Use the generator of mybatis to automatically generate code, but in the Oracle database, number (6, 2) is always automatically converted to bigdecimal, and I want to convert it to float type
In this way, a type converter needs to inherit the javatyperesolver interface.
Add the type conversion configuration location in the mybaties configuration file generatorconfig. xml.
<Javatyperesolver type = "com. generator. myjavatyperesolver"> <property name = "forcebigdecimals" value = "false"/> <! -- Type parser --> </javatyperesolver>
Main Code of type converter myjavatyperesolver
Public fullyqualifiedjavatype calculatejavatype (introspectedcolumn) {// todo auto-generated method stub fullyqualifiedjavatype answer; jdbctypeinformation = typemap. get (introspectedcolumn. getjdbctype (); If (jdbctypeinformation = NULL) {Switch (introspectedcolumn. getjdbctype () {case types. decimal: Case types. numeric: If (introspectedcolumn. getscale ()> 0) {// convert to float answer = new fullyqualifiedjavatype (float. class. getname ();} else {If (introspectedcolumn. getlength ()> 18 | forcebigdecimals) {answer = new fullyqualifiedjavatype (bigdecimal. class. getname ();} else if (introspectedcolumn. getlength ()> 9) {answer = new fullyqualifiedjavatype (Long. class. getname ();} else if (introspectedcolumn. getlength ()> 4) {answer = new fullyqualifiedjavatype (integer. class. getname ();} else {answer = new fullyqualifiedjavatype (short. class. getname () ;}} break; default: Answer = NULL; break ;}} else {answer = jdbctypeinformation. getfullyqualifiedjavatype ();} return answer ;}
Type conversion when mybatis uses generator to automatically generate code