2020-07-01 15:22:07 +08:00
2020-07-01 15:22:07 +08:00
2020-07-01 15:22:07 +08:00
2020-07-01 15:22:07 +08:00
2020-07-01 15:22:07 +08:00
2020-07-01 15:22:07 +08:00
2020-06-30 17:34:47 +08:00
2020-07-01 15:22:07 +08:00
2020-07-01 15:22:07 +08:00
2020-07-01 15:22:07 +08:00
2020-07-01 15:22:07 +08:00
2020-07-01 15:22:07 +08:00
2020-07-01 15:22:07 +08:00

Corona

IDEA 环境需求

由于项目依赖org.projectlombok:lombok:1.18.2,而Lombok1.18.4版本做了重设计,不兼容之前版本,因此IDEALombok插件必须是版本lombok-plugin-0.23,这里比较坑,如果升级到版本1.18.4以后插件还是得升级而且很多API都要改。

插件下载地址:https://pan.caimi-inc.com/d/b038610394/

下载对应版本插件,比如IDEA 2018.2.x下载lombok-plugin-0.23-2018.2.zip,卸载IDEA已安装Lombok插件,选择磁盘安装,如下图: 安装Lombok插件

启动SpringBoot项目

建议先执行mvn编译命令比如编译模块CMS

mvn clean compile -am -pl cms -T 2C

Tigon

Controller

如果加注了@ResponseBody或者@RestController,不做变动,依循Spring MVC方式JSON序列化返回数据,否则返回Wacai接口规范数据格式,如下例:

@ResponseBody

@ResponseBody
@RequestMapping("/resp-body")
public String respBody() {
    return "Response Body";
}

响应输出

Response Body

Wacai JSON API

@RequestMapping("/resp-body")
public String respBody() {
    return "Response Body";
}

响应输出

{
    "code": 0,
    "success": true,
    "data": "Response Body"
}

简单来说就是,不加@ResponseBody注解,默认会以WacaiAPI规范响应数据结果。

参见以下样例:

I.

@RequestMapping("/count")
public int count() {
    return 1024;
}

响应输出

{
    "code": 0,
    "success": true,
    "data": 1024
}

II.

@RequestMapping("/user-info")
public Map<String, Object> userInfo() {
    final Map<String, Object> user = new HashMap<>(4);
    user.put("name", "Uncle Donghuang");
    user.put("gender", "MALE");
    user.put("mobile", "17161787481");
    user.put("active", true);
    return user;
}

响应输出

{
    "code": 0,
    "success": true,
    "data": {
        "name": "Uncle Donghuang",
        "gender": "MALE",
        "mobile": "17161787481",
        "active": true,
    }
}

III.

@RequestMapping("/error-caused")
public Map<String, Object> errorCaused() {
    throw new RuntimeException("Oops, some error caused");
}

响应输出

{
    "code": 5000,
    "success": false,
    "message": "Oops, some error caused"
}

MyBatis

MyBatis做了启动期增强,实例Mapper继承了BaseMapper之后,会继承获得相关的增删改查等方法,如下例:

Model
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
import com.wacai.tigon.model.M0;
import com.wacai.tigon.mybatis.Table;
import com.wacai.tigon.mybatis.NotUpdate;
import lombok.experimental.FieldNameConstants;

@Getter
@Setter
@Table("yo_customer")
@FieldNameConstants(prefix = "")
public class Customer extends M0<Integer> {
    private String name;
    private String account;
    private String password;
    private String note;
    @NotUpdate
    protected Date createdTime;
    protected Date updatedTime;
    @NotUpdate
    protected String createdBy;
    protected String updatedBy;
    protected boolean active;
}
Mapper
import com.wacai.tigon.mybatis.BaseMapper;

public interface CustomerMapper extends BaseMapper<Integer, Customer> {
}
Mapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.wacai.loan.yo.mapper.CustomerMapper">
</mapper>
Usage
@Autowired
private CustomerMapper customerMapper;

I. 插入

final Customer customer = new Customer();
customer.setName("Uncle Donghuang");
customer.setAccount("donghuang");
customer.setPassword("qR$#FzM!z9W*");
customer.setCreatedBy("SYS");
customer.setCreatedTime(new Date());
customer.setActive(true);
customerMapper.insert(customer);

II. 查询

Find by ID

final Integer id = 1154;
final Customer customer = customerMapper.find(id);

Find by Search

final Customer customer = customerMapper.find(
    new Search(Customer.ACCOUNT, "donghuang")
            .eq(Customer.ACTIVE, true));

List by Search

final List<Customer> customers = customerMapper.list(
    new Search(Customer.ACTIVE, true)
            .between(Customer.ID, 1, 1154)
            .asc(Customer.ACCOUNT)
            .limit(42));

Search API

  • and And another Search
  • asc Order ASC
  • between Between two values
  • contains Value contains string
  • desc Order DSC
  • endsWith Value ends with string
  • eq Eqauls
  • gt Greater than
  • gte Eqauls or greater than
  • in In values
  • isNull Value is null
  • like Value like
  • limit Return rows limit
  • lt Less than
  • lte Eqauls or less than
  • ne Not equals
  • notIn Not in values
  • notNull Value is not null
  • offset Return rows offset
  • or Or another Search
  • orderBy Order by
  • startsWith Value starts with string

III. 更新

Update model

Customer customer = customerMapper.find(
    new Search(Customer.ACCOUNT, "donghuang")
            .eq(Customer.ACTIVE, true));

customer.setPassword("g!5KpWdXEB!^");
customer.setUpdatedBy("SYS");
customer.setUpdatedTime(new Date());
customerMapper.update(customer);

Update with map

final Map<String, Object> update = new HashMap<>(4);
update.put(Customer.PASSWORD, "g!5KpWdXEB!^");
update.put(Customer.UPDATED_BY, "SYS");
update.put(Customer.UPDATED_TIME, new Date());

customerMapper.update(update, 1154);
// OR
// customerMapper.update(update, new Search(Customer.ID, 1154));

Set null

// Update note to null of customer 1154
customerMapper.setNull(Customer.NOTE, 1154);
// Update note to null of customer 1154
customerMapper.setNull(Customer.NOTE, new Search(Customer.ID, 1154));
// Update note to null of all
customerMapper.setNull(Customer.NOTE, new Search());

IV. 删除

Delete by ID

customerMapper.delete(1154);

Delete by Search

customerMapper.delete(new Search(Customer.ID, 1154));
Description
No description provided
Readme 66 MiB
Languages
JavaScript 48.2%
CSS 20%
Java 19.1%
Less 8.5%
Handlebars 3.7%
Other 0.4%