mybatis-universal-crud


License

License

Categories

Categories

MyBatis Data ORM
GroupId

GroupId

org.linuxprobe
ArtifactId

ArtifactId

mybatis-universal-crud
Last Version

Last Version

2.3.1.RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

mybatis-universal-crud
mybatis-universal-crud

Download mybatis-universal-crud

How to add to project

<!-- https://jarcasting.com/artifacts/org.linuxprobe/mybatis-universal-crud/ -->
<dependency>
    <groupId>org.linuxprobe</groupId>
    <artifactId>mybatis-universal-crud</artifactId>
    <version>2.3.1.RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/org.linuxprobe/mybatis-universal-crud/
implementation 'org.linuxprobe:mybatis-universal-crud:2.3.1.RELEASE'
// https://jarcasting.com/artifacts/org.linuxprobe/mybatis-universal-crud/
implementation ("org.linuxprobe:mybatis-universal-crud:2.3.1.RELEASE")
'org.linuxprobe:mybatis-universal-crud:jar:2.3.1.RELEASE'
<dependency org="org.linuxprobe" name="mybatis-universal-crud" rev="2.3.1.RELEASE">
  <artifact name="mybatis-universal-crud" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.linuxprobe', module='mybatis-universal-crud', version='2.3.1.RELEASE')
)
libraryDependencies += "org.linuxprobe" % "mybatis-universal-crud" % "2.3.1.RELEASE"
[org.linuxprobe/mybatis-universal-crud "2.3.1.RELEASE"]

Dependencies

compile (14)

Group / Artifact Type Version
org.linuxprobe : mybatis-universal-crud-base jar 0.0.1.RELEASE
org.springframework : spring-jdbc jar 5.2.8.RELEASE
org.springframework : spring-context jar 5.2.8.RELEASE
org.projectlombok : lombok jar 1.18.12
org.mybatis : mybatis jar 3.5.3
org.mybatis : mybatis-spring jar 2.0.3
org.slf4j : slf4j-api jar 1.7.30
org.reflections : reflections jar 0.9.11
com.google.guava : guava jar 28.0-jre
javax.validation : validation-api jar 2.0.1.Final
org.hibernate.validator : hibernate-validator jar 6.0.17.Final
org.linuxprobe : luava-reflection jar 0.0.5.RELEASE
org.linuxprobe : luava-proxy jar 0.0.2.RELEASE
org.linuxprobe : luava-other jar 0.0.3.RELEASE

Project Modules

There are no modules declared in this project.

简介:

该项目基于mybatis封装, 目前只支持mysql, 旨在提供一个对dao层通用的操作,支持普通java程序和spring程序.

1 特性:

  1. 关键字转义,防止sql注入;
  2. 注解支持;
  3. 查询, 普通条件查询, 连表查询, 懒加载;
  4. 更新, 替换更新和非空字段更新;
  5. 插入, 单条插入, 批量插入,指定枚举处理, 时间处理, boolean处理;
  6. 删除, 根据主键删除;
  7. 实体字段支持javax.validation验证。

2 使用

2.1 和spring集成

2.1.1 maven依赖

<dependency>
	<groupId>org.linuxprobe</groupId>
	<artifactId>mybatis-universal-crud</artifactId>
	<version>2.2.1.RELEASE</version>
</dependency>

2.1.2 spring xml配置文件加入

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
    <aop:aspectj-autoproxy poxy-target-class="true"></aop:aspectj>
    <!-- datasource的配置省略 -->
    <bean id="datasource" class="com.zaxxer.hikari.HikariDataSource"></bean>
    <bean name="sqlSessionFactory" class="org.linuxprobe.crud.mybatis.spring.UniversalCrudSqlSessionFactoryBean">
        <property name="dataSource" ref="datasource"></property>
        <property name="universalCrudScan" value="org.linuxprobe.crud.demo.model;org.linuxprobe.crud.demo.query"></property>
        <property name="configLocation" value="classpath:mybatis-config.xml"></property>
        <!-- 扫描sql配置文件:mapper需要的xml文件 -->
        <property name="mapperLocations" value="classpath:mapper/*.xml"></property>
    </bean>
	<bean name="sqlSessionTemplaten" class="org.linuxprobe.crud.mybatis.spring.UniversalCrudSqlSessionTemplaten">
        <constructor-arg ref="sqlSessionFactory"></constructor>
    </bean>
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="org.linuxprobe.**.mapper"></property>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>
</beans>

2.2 和spring boot集成

2.2.1 pom引入spring boot专用依赖

<dependency>
	<groupId>org.linuxprobe</groupId>
	<artifactId>
		mybatis-universal-crud-spring-boot-starter
	</artifactId>
	<version>2.1.8.RELEASE</version>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

2.2.2 yml配置

mybatis:
  mapperLocations: classpath*:org/linuxprobe/**/mapping/*.xml
  configLocation: classpath:/mybatis-config.xml
  #配置查询类所在包, 实体所在包, 可配置多个
  universalCrudScans:
    - org.linuxprobe.universalcrudspringbootdemo.query
    - org.linuxprobe.universalcrudspringbootdemo.model

2.2.3 启用类添加注解

@EnableAspectJAutoProxy(exposeProxy = true)
/** 此处指定你的mapper接口所在包 */
@MapperScan(basePackages = "org.linuxprobe")

2.3 crud示例

2.3.1 新建实体类

urer实体

package org.linuxprobe.universalcrudspringbootdemo.model;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.linuxprobe.crud.core.annoatation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 使用@Entity标注一个实体;
 * 使用@Table指定对应的表名
 */
@Entity
@Table(value = "permission")
@Getter
@Setter
@Accessors(chain = true)
public class User {
    @PrimaryKey(PrimaryKey.Strategy.NATIVE)
    private Integer id;

    private String name;

    private List<Role> roles;
    /**
     * 使用@Column指定列明;
     * 使用@EnumHandler来指定枚举的保存方式
     */
    @Column("sex")
    @NotNull
    @EnumHandler(EnumHandler.EnumCustomerType.Ordinal)
    private Sex xingbie;

    public static enum Sex {
        Man,
        WoMan
    }
}

Versions

Version
2.3.1.RELEASE
2.3.0.RELEASE
2.2.6.RELEASE
2.2.5.RELEASE
2.2.4.RELEASE
2.2.3.RELEASE
2.2.2.RELEASE
2.2.1.RELEASE
2.2.0.RELEASE
2.1.9.RELEASE
2.1.8.RELEASE
2.1.7.RELEASE
2.1.6.RELEASE
2.1.5.RELEASE
2.1.4.RELEASE
2.1.3.RELEASE
2.1.2.RELEASE
2.1.1.RELEASE
2.1.0.RELEASE
2.0.9.RELEASE
2.0.8.RELEASE
2.0.7.RELEASE
2.0.6.RELEASE
2.0.5.RELEASE
2.0.4.RELEASE
2.0.3.RELEASE
2.0.2.RELEASE
2.0.1.RELEASE
2.0.0.RELEASE