mybatis-common-mapper

mybatis common-mapper

License

License

Categories

Categories

MyBatis Data ORM
GroupId

GroupId

io.github.jaspercloud
ArtifactId

ArtifactId

mybatis-common-mapper
Last Version

Last Version

1.2
Release Date

Release Date

Type

Type

jar
Description

Description

mybatis-common-mapper
mybatis common-mapper
Project URL

Project URL

https://github.com/open-creation/common-mapper
Source Code Management

Source Code Management

https://github.com/jaspercloud/common-mapper

Download mybatis-common-mapper

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.jaspercloud/mybatis-common-mapper/ -->
<dependency>
    <groupId>io.github.jaspercloud</groupId>
    <artifactId>mybatis-common-mapper</artifactId>
    <version>1.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.jaspercloud/mybatis-common-mapper/
implementation 'io.github.jaspercloud:mybatis-common-mapper:1.2'
// https://jarcasting.com/artifacts/io.github.jaspercloud/mybatis-common-mapper/
implementation ("io.github.jaspercloud:mybatis-common-mapper:1.2")
'io.github.jaspercloud:mybatis-common-mapper:jar:1.2'
<dependency org="io.github.jaspercloud" name="mybatis-common-mapper" rev="1.2">
  <artifact name="mybatis-common-mapper" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.jaspercloud', module='mybatis-common-mapper', version='1.2')
)
libraryDependencies += "io.github.jaspercloud" % "mybatis-common-mapper" % "1.2"
[io.github.jaspercloud/mybatis-common-mapper "1.2"]

Dependencies

compile (2)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter jar 2.0.3.RELEASE
javax.persistence : persistence-api jar 1.0

provided (1)

Group / Artifact Type Version
org.mybatis.spring.boot : mybatis-spring-boot-starter jar 1.3.2

Project Modules

There are no modules declared in this project.

common-mapper MyBatis通用Mapper

Example

CommonMapper commonMapper = context.getBean(CommonMapper.class);

//保存
User user = new User();
user.setUserName("test");
user.setPassWord("test");
user.setSex("");
user.setUserMark("test");
commonMapper.insert(User.class, user);

//查询
User user = new User();
user.setUserName("test");
user.setPassWord("test");
User result = commonMapper.selectOne(User.class, user);

//更新
User user = new User();
user.setId(1L);
user.setUserName("test");
user.setPassWord("test");
user.setSex("");
user.setUserMark("test");
commonMapper.updateNotNullById(User.class, user);

entity定义

/**
 * @Cacheable 是否缓存(不缓存不加)
 */
@Cacheable
/**
 * 表名映射
 */
@Entity(name = "t_user")
public class User {

    /**
     * 主键生成
     */
    @GeneratedValue(generator = "select nextval('seq_user')")
    /**
     * 主键
     */
    @Id
    /**
     * 字段映射
     */
    @Column
    private Long id;

    @Column(name = "username")
    private String userName;

    @Column(name = "password")
    private String passWord;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassWord() {
        return passWord;
    }

    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }
    
    public User() {
    }
}

通用方法

/**
 * 保存
 *
 * @param clazz
 * @param obj
 */
void insert(Class<?> clazz, @Param(PARAM) Object obj);

/**
 * 根据主键更新所有的属性(包括空值)
 *
 * @param clazz
 * @param obj
 */
void updateAllById(Class<?> clazz, @Param(PARAM) Object obj);

/**
 * 根据主键更新不为空的属性
 *
 * @param clazz
 * @param obj
 */
void updateNotNullById(Class<?> clazz, @Param(PARAM) Object obj);

/**
 * 根据主键删除
 *
 * @param clazz
 * @param id
 */
void deleteById(Class<?> clazz, @Param(PARAM) Long id);

/**
 * 根据不为空的属性删除
 *
 * @param clazz
 * @param obj
 */
void delete(Class<?> clazz, @Param(PARAM) Object obj);

/**
 * 根据主键查询
 *
 * @param clazz
 * @param id
 * @param <T>
 * @return
 */
<T> T selectOneById(Class<T> clazz, @Param(PARAM) Long id);

/**
 * 根据不为空的属性查询一个
 *
 * @param clazz
 * @param obj
 * @param <T>
 * @return
 */
<T> T selectOne(Class<T> clazz, @Param(PARAM) Object obj);

/**
 * 根据不为空的属性查询集合
 *
 * @param clazz
 * @param obj
 * @param <T>
 * @return
 */
<T> List<T> select(Class<T> clazz, @Param(PARAM) Object obj);

/**
 * 查询所有
 *
 * @param clazz
 * @param <T>
 * @return
 */
<T> List<T> selectAll(Class<T> clazz);

/**
 * 获取记录数
 *
 * @param clazz
 * @return
 */
long count(Class<?> clazz);

Versions

Version
1.2