Giter Site home page Giter Site logo

simplecurd's Introduction

前言

使用Mybatis,通常需要写Entity,Mapper(java、xml),对于小项目很麻烦,有没有只写Entity就可以进行CURD呢?答案是肯定的。

我们的需求

1、只写少量代码,实现CURD
2、少量配置,完成类似Wrapper
3、无缝兼容原有的Mapper
4、再包含通用Mapper?

实现结果

上述需求可以完全满足,而且只需要2个类就搞定上面的需求

1、只需要定义一个 pojo ,就可以完成CURD

@Table(name = "user")
public class User {
    String id;
    String name;
    String phone;
}

2、类似baseMapper使用,直接注入(无需写UserMapper)

@Resource
BaseMapper<User> userBaseMapper;

3、简单Wrapper

User user = new User();
Dal.with(User.class).select(user);

4、实现动态SQL查询

User user = new User();
Dal.with(User.class).query(sql -> sql.SELECT("id,name").WHERE("name=#{name}"), user);

项目代码

├── java
│   └── com
│       └── demo
│           ├── SimpleCurdApplication.java
│           ├── core
│           │   ├── BaseMapper.java
│           │   ├── Dal.java
│           │   └── SpringUtil.java
│           └── web
│               ├── SimpleCurdController.java
│               └── User.java
└── resources
    └── application.yml

代码

https://github.com/scofier/SimpleCurd

simplecurd's People

Contributors

scofier avatar

Watchers

James Cloos 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.