Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8861305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:27:50+00:00 2026-06-14T15:27:50+00:00

I am using MyBatis with MySql in my project. I have: myField ENUM(‘yes’,’no’) and

  • 0

I am using MyBatis with MySql in my project.

I have:

myField ENUM(‘yes’,’no’)

and I want to map in to java boolean value:

I know I can modify all mybatis templates, e.g.:

<update id="update">
UPDATE
myTable
   <set>
        ...
       <if test="myField != null">myField = <choose>
           <when test="myField == true">'yes'</when>
           <otherwise>'no'</otherwise>
           </choose>,
        </if>
        ...
    </set>
 WHERE
    ...
 </update>

But can I do this in more convenient way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:27:51+00:00Added an answer on June 14, 2026 at 3:27 pm

    It seems the best way to solve this is to implement my own boolean type handler:

    public class YesNoBooleanTypeHandler extends BaseTypeHandler<Boolean> {
    
        @Override
        public void setNonNullParameter(PreparedStatement ps, int i, Boolean parameter,      JdbcType jdbcType)
                throws SQLException {
            ps.setString(i, convert(parameter));
        }
    
        @Override
        public Boolean getNullableResult(ResultSet rs, String columnName)
                throws SQLException {
            return convert(rs.getString(columnName));
        }
    
        @Override
        public Boolean getNullableResult(ResultSet rs, int columnIndex)
                throws SQLException {
            return convert(rs.getString(columnIndex));
        }
    
        @Override
        public Boolean getNullableResult(CallableStatement cs, int columnIndex)
                throws SQLException {
            return convert(cs.getString(columnIndex));
        }
    
        private String convert(Boolean b) {
            return b ? "yes" : "no";
        }
    
        private Boolean convert(String s) {
            return s.equals("yes");
        }
    
    }
    

    and then to use it in the mapper template:

    <update id="update">
    UPDATE
    myTable
       <set>
            ...
           <if test="myField != null">myField = #{myField ,typeHandler=YesNoBooleanTypeHandler}</if>
            ...
        </set>
     WHERE
        ...
     </update>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have swing app and I am using mybatis: public class MyAppCView
I want to build an application using Hibernate and MyBatis integrate with Spring. In
I want to define a new Java class at runtime using some input information,
(Using MyBatis v3.0.4.) I have a problem that I do not know how to
So I'm working on a side project using MySQL/MyBatis3/Tomcat. I'm currently working on turning
I am using MyBatis 3.0.3 and have problem: some columns in database have names
I have web application which using spring wicket and sql-processor (similar to mybatis) which
we using mybatis 3.1.1. we found for oracle the result map returned contains column
We're using MyBatis (3.0.5) as our or-mapping tool (and I don't have any say-so
I want to Pass 'Map' to an PL/SQL Stored Procedure via Spring Mybatis Mapper

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.