Type conversion when mybatis uses generator to automatically generate code

Source: Internet
Author: User

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

Related Article

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.