Code Monkey home page Code Monkey logo

enumhandler's Introduction

MyBatis通用枚举处理器

MyBatis EnumHandler

Build Status Coverage Status Dependency Status Maven central License Stack Overflow Project Stats

mybatis


Document:


描述:主要是为了对枚举进行通用处理,Mybatis提供的EnumTypeHandler和EnumOrdinalTypeHandler使用还是不够灵活。

1. 使用举例

查询1:
List<User> selectByUserType(UserType userType);
<select id="selectByUserType" resultMap="BaseResultMap">
	select * from user_enum where user_type=#{userType,typeHandler=com.chrhc.mybatis.handler.EnumHandler}
</select>
查询2:
User selectById(@Param("id") int id);
<select id="selectById" resultMap="BaseResultMap">
	select * from user_enum where id = #{id}
</select>
<resultMap id="BaseResultMap" type="User">
	<id column="id" property="id"/>
	<result column="name" property="name"/>
	<result column="password" property="password"/>
	<result column="user_type" property="userType" typeHandler="com.chrhc.mybatis.handler.EnumHandler"/>
</resultMap>
插入:
Integer insertUser(User user);
<insert id="insertUser" parameterType="User">
	insert into user_enum(id, name, password, user_type)values(#{id}, #{name}, #{password}, #{userType,typeHandler=com.chrhc.mybatis.handler.EnumHandler})
</insert>

2.使用条件

枚举类需要实现com.chrhc.mybatis.handler.Identifiable接口,仅此而已。

3.关于作者:

作者QQ:605162215
作者邮箱:[email protected]

enumhandler's People

Contributors

xjs1919 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.