修复通俗重量
This commit is contained in:
		@@ -1,34 +1,42 @@
 | 
			
		||||
package com.stdiet.custom.domain;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang3.builder.ToStringBuilder;
 | 
			
		||||
import org.apache.commons.lang3.builder.ToStringStyle;
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonFormat;
 | 
			
		||||
import com.stdiet.common.annotation.Excel;
 | 
			
		||||
import com.stdiet.common.core.domain.BaseEntity;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 菜品对象 sys_dishes
 | 
			
		||||
 * 
 | 
			
		||||
 *
 | 
			
		||||
 * @author wonder
 | 
			
		||||
 * @date 2020-12-28
 | 
			
		||||
 */
 | 
			
		||||
public class SysDishes extends BaseEntity
 | 
			
		||||
{
 | 
			
		||||
@Data
 | 
			
		||||
public class SysDishes {
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    /** id */
 | 
			
		||||
    /**
 | 
			
		||||
     * id
 | 
			
		||||
     */
 | 
			
		||||
    private Long id;
 | 
			
		||||
 | 
			
		||||
    /** 菜品名称 */
 | 
			
		||||
    /**
 | 
			
		||||
     * 菜品名称
 | 
			
		||||
     */
 | 
			
		||||
    @Excel(name = "菜品名称")
 | 
			
		||||
    private String name;
 | 
			
		||||
 | 
			
		||||
    /** 菜品类型 */
 | 
			
		||||
    /**
 | 
			
		||||
     * 菜品类型
 | 
			
		||||
     */
 | 
			
		||||
    @Excel(name = "菜品类型")
 | 
			
		||||
    private String type;
 | 
			
		||||
 | 
			
		||||
    /** 做法 */
 | 
			
		||||
    /**
 | 
			
		||||
     * 做法
 | 
			
		||||
     */
 | 
			
		||||
    @Excel(name = "做法")
 | 
			
		||||
    private String methods;
 | 
			
		||||
 | 
			
		||||
@@ -36,80 +44,36 @@ public class SysDishes extends BaseEntity
 | 
			
		||||
 | 
			
		||||
    private String reviewStatus;
 | 
			
		||||
 | 
			
		||||
    public Integer getIsMain() {
 | 
			
		||||
        return isMain;
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 创建者
 | 
			
		||||
     */
 | 
			
		||||
    private String createBy;
 | 
			
		||||
 | 
			
		||||
    public void setIsMain(Integer isMain) {
 | 
			
		||||
        this.isMain = isMain;
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 创建时间
 | 
			
		||||
     */
 | 
			
		||||
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 | 
			
		||||
    private Date createTime;
 | 
			
		||||
 | 
			
		||||
    public void setReviewStatus(String reviewStatus) {
 | 
			
		||||
        this.reviewStatus = reviewStatus;
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 更新者
 | 
			
		||||
     */
 | 
			
		||||
    private String updateBy;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 更新时间
 | 
			
		||||
     */
 | 
			
		||||
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 | 
			
		||||
    private Date updateTime;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 备注
 | 
			
		||||
     */
 | 
			
		||||
    private String remark;
 | 
			
		||||
 | 
			
		||||
    public String getReviewStatus() {
 | 
			
		||||
        return reviewStatus;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private List<SysDishesIngredient> igdList;
 | 
			
		||||
 | 
			
		||||
    public void setId(Long id) 
 | 
			
		||||
    {
 | 
			
		||||
        this.id = id;
 | 
			
		||||
    }
 | 
			
		||||
    private List<SysDishesIngredient> detail;
 | 
			
		||||
 | 
			
		||||
    public Long getId() 
 | 
			
		||||
    {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
    public void setName(String name) 
 | 
			
		||||
    {
 | 
			
		||||
        this.name = name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getName() 
 | 
			
		||||
    {
 | 
			
		||||
        return name;
 | 
			
		||||
    }
 | 
			
		||||
    public void setType(String type) 
 | 
			
		||||
    {
 | 
			
		||||
        this.type = type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getType() 
 | 
			
		||||
    {
 | 
			
		||||
        return type;
 | 
			
		||||
    }
 | 
			
		||||
    public void setMethods(String methods) 
 | 
			
		||||
    {
 | 
			
		||||
        this.methods = methods;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getMethods() 
 | 
			
		||||
    {
 | 
			
		||||
        return methods;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setIgdList(List<SysDishesIngredient> ingredientList) {
 | 
			
		||||
        this.igdList = ingredientList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<SysDishesIngredient> getIgdList() {
 | 
			
		||||
        return igdList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
 | 
			
		||||
            .append("id", getId())
 | 
			
		||||
            .append("name", getName())
 | 
			
		||||
            .append("type", getType())
 | 
			
		||||
            .append("methods", getMethods())
 | 
			
		||||
            .append("createBy", getCreateBy())
 | 
			
		||||
            .append("createTime", getCreateTime())
 | 
			
		||||
            .append("updateBy", getUpdateBy())
 | 
			
		||||
            .append("updateTime", getUpdateTime())
 | 
			
		||||
            .toString();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -21,9 +21,9 @@ public class SysDishesIngredient extends SysIngredient {
 | 
			
		||||
 | 
			
		||||
    private Long cusUnit;
 | 
			
		||||
 | 
			
		||||
    private BigDecimal cusWeight;
 | 
			
		||||
//    private BigDecimal cusWeight;
 | 
			
		||||
 | 
			
		||||
    private Integer cusWei;
 | 
			
		||||
    private Integer cusWeight;
 | 
			
		||||
 | 
			
		||||
    private BigDecimal weight;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,25 @@
 | 
			
		||||
package com.stdiet.custom.domain;
 | 
			
		||||
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 食材对象 sys_ingredient
 | 
			
		||||
 *
 | 
			
		||||
 * @author wonder
 | 
			
		||||
 * @date 2020-12-15
 | 
			
		||||
 */
 | 
			
		||||
@Data
 | 
			
		||||
public class SysDishesIngredientInfo {
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    private Long id;
 | 
			
		||||
 | 
			
		||||
    private String cus_unit;
 | 
			
		||||
 | 
			
		||||
    private String cus_weight;
 | 
			
		||||
 | 
			
		||||
    private Integer weight;
 | 
			
		||||
 | 
			
		||||
    private String remark;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -1,11 +1,11 @@
 | 
			
		||||
package com.stdiet.custom.domain;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonFormat;
 | 
			
		||||
import com.stdiet.common.annotation.Excel;
 | 
			
		||||
import com.stdiet.common.core.domain.BaseEntity;
 | 
			
		||||
import org.apache.commons.lang3.builder.ToStringBuilder;
 | 
			
		||||
import org.apache.commons.lang3.builder.ToStringStyle;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
 | 
			
		||||
import java.math.BigDecimal;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 食材对象 sys_ingredient
 | 
			
		||||
@@ -13,12 +13,10 @@ import java.math.BigDecimal;
 | 
			
		||||
 * @author wonder
 | 
			
		||||
 * @date 2020-12-15
 | 
			
		||||
 */
 | 
			
		||||
public class SysIngredient extends BaseEntity {
 | 
			
		||||
@Data
 | 
			
		||||
public class SysIngredient {
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    private int pageNum;
 | 
			
		||||
    private int pageSize;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * id
 | 
			
		||||
     */
 | 
			
		||||
@@ -77,131 +75,36 @@ public class SysIngredient extends BaseEntity {
 | 
			
		||||
     */
 | 
			
		||||
    private String reviewStatus;
 | 
			
		||||
 | 
			
		||||
    public void setReviewStatus(String reviewStatus) {
 | 
			
		||||
        this.reviewStatus = reviewStatus;
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * 创建者
 | 
			
		||||
     */
 | 
			
		||||
    private String createBy;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 创建时间
 | 
			
		||||
     */
 | 
			
		||||
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 | 
			
		||||
    private Date createTime;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 更新者
 | 
			
		||||
     */
 | 
			
		||||
    private String updateBy;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 更新时间
 | 
			
		||||
     */
 | 
			
		||||
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 | 
			
		||||
    private Date updateTime;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 备注
 | 
			
		||||
     */
 | 
			
		||||
    private String remark;
 | 
			
		||||
 | 
			
		||||
    public String getReviewStatus() {
 | 
			
		||||
        return reviewStatus;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Long[] recIds;
 | 
			
		||||
 | 
			
		||||
    private Long[] notRecIds;
 | 
			
		||||
 | 
			
		||||
    public Long[] getRecIds() {
 | 
			
		||||
        return recIds;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Long[] getNotRecIds() {
 | 
			
		||||
        return notRecIds;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Long getId() {
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setId(Long id) {
 | 
			
		||||
        this.id = id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getName() {
 | 
			
		||||
        return name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setName(String name) {
 | 
			
		||||
        this.name = name;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getType() {
 | 
			
		||||
        return type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setType(String type) {
 | 
			
		||||
        this.type = type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public BigDecimal getProteinRatio() {
 | 
			
		||||
        return proteinRatio;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setProteinRatio(BigDecimal proteinRatio) {
 | 
			
		||||
        this.proteinRatio = proteinRatio;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public BigDecimal getFatRatio() {
 | 
			
		||||
        return fatRatio;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setFatRatio(BigDecimal fatRatio) {
 | 
			
		||||
        this.fatRatio = fatRatio;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public BigDecimal getCarbonRatio() {
 | 
			
		||||
        return carbonRatio;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCarbonRatio(BigDecimal carbonRatio) {
 | 
			
		||||
        this.carbonRatio = carbonRatio;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getArea() {
 | 
			
		||||
        return area;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setArea(String area) {
 | 
			
		||||
        this.area = area;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getNotRec() {
 | 
			
		||||
        return notRec;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNotRec(String notRec) {
 | 
			
		||||
        this.notRec = notRec;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getRec() {
 | 
			
		||||
        return rec;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRec(String rec) {
 | 
			
		||||
        this.rec = rec;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPageNum(int pageNum) {
 | 
			
		||||
        this.pageNum = pageNum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPageSize(int pageSize) {
 | 
			
		||||
        this.pageSize = pageSize;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getPageNum() {
 | 
			
		||||
        return pageNum;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getPageSize() {
 | 
			
		||||
        return pageSize;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String toString() {
 | 
			
		||||
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
 | 
			
		||||
                .append("id", getId())
 | 
			
		||||
                .append("name", getName())
 | 
			
		||||
                .append("type", getType())
 | 
			
		||||
                .append("proteinRatio", getProteinRatio())
 | 
			
		||||
                .append("fatRatio", getFatRatio())
 | 
			
		||||
                .append("carbonRatio", getCarbonRatio())
 | 
			
		||||
                .append("remark", getRemark())
 | 
			
		||||
                .append("area", getArea())
 | 
			
		||||
                .append("notRec", getNotRec())
 | 
			
		||||
                .append("recommend", getRec())
 | 
			
		||||
                .append("createBy", getCreateBy())
 | 
			
		||||
                .append("createTime", getCreateTime())
 | 
			
		||||
                .append("updateBy", getUpdateBy())
 | 
			
		||||
                .append("updateTime", getUpdateTime())
 | 
			
		||||
                .toString();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,47 @@
 | 
			
		||||
package com.stdiet.custom.domain;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.annotation.JsonFormat;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@Data
 | 
			
		||||
public class SysRecipes {
 | 
			
		||||
    private static final long serialVersionUID = 1L;
 | 
			
		||||
 | 
			
		||||
    private Long id;
 | 
			
		||||
 | 
			
		||||
    private Integer numDay;
 | 
			
		||||
 | 
			
		||||
    private List<SysDishes> dishes;
 | 
			
		||||
 | 
			
		||||
    private Integer reviewStatus;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 创建者
 | 
			
		||||
     */
 | 
			
		||||
    private String createBy;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 创建时间
 | 
			
		||||
     */
 | 
			
		||||
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 | 
			
		||||
    private Date createTime;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 更新者
 | 
			
		||||
     */
 | 
			
		||||
    private String updateBy;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 更新时间
 | 
			
		||||
     */
 | 
			
		||||
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
 | 
			
		||||
    private Date updateTime;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 备注
 | 
			
		||||
     */
 | 
			
		||||
    private String remark;
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,10 @@
 | 
			
		||||
package com.stdiet.custom.mapper;
 | 
			
		||||
 | 
			
		||||
import com.stdiet.custom.domain.SysRecipes;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public interface SysRecipesMapper {
 | 
			
		||||
 | 
			
		||||
    public List<SysRecipes> selectSysRecipesByRecipesId(Long id);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,9 @@
 | 
			
		||||
package com.stdiet.custom.service;
 | 
			
		||||
 | 
			
		||||
import com.stdiet.custom.domain.SysRecipes;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public interface ISysRecipesService {
 | 
			
		||||
    public List<SysRecipes> selectSysRecipesByRecipesId(Long id);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,23 @@
 | 
			
		||||
package com.stdiet.custom.service.impl;
 | 
			
		||||
 | 
			
		||||
import com.stdiet.custom.domain.SysRecipes;
 | 
			
		||||
import com.stdiet.custom.mapper.SysRecipesMapper;
 | 
			
		||||
import com.stdiet.custom.service.ISysRecipesService;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Service;
 | 
			
		||||
import org.springframework.transaction.annotation.Transactional;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@Transactional
 | 
			
		||||
public class SysRecipesServiceImpl implements ISysRecipesService {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private SysRecipesMapper sysRecipesMapper;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public List<SysRecipes> selectSysRecipesByRecipesId(Long id) {
 | 
			
		||||
        return sysRecipesMapper.selectSysRecipesByRecipesId(id);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,56 @@
 | 
			
		||||
package com.stdiet.custom.typehandler;
 | 
			
		||||
 
 | 
			
		||||
import com.alibaba.fastjson.JSONArray;
 | 
			
		||||
import org.apache.ibatis.type.BaseTypeHandler;
 | 
			
		||||
import org.apache.ibatis.type.JdbcType;
 | 
			
		||||
import org.apache.ibatis.type.MappedJdbcTypes;
 | 
			
		||||
import org.apache.ibatis.type.MappedTypes;
 | 
			
		||||
 
 | 
			
		||||
import java.sql.CallableStatement;
 | 
			
		||||
import java.sql.PreparedStatement;
 | 
			
		||||
import java.sql.ResultSet;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
 
 | 
			
		||||
/**
 | 
			
		||||
 * Created by lixio on 2019/3/28 20:51
 | 
			
		||||
 * @description 用以mysql中json格式的字段,进行转换的自定义转换器,转换为实体类的JSONArray属性
 | 
			
		||||
 * MappedTypes注解中的类代表此转换器可以自动转换为的java对象
 | 
			
		||||
 * MappedJdbcTypes注解中设置的是对应的jdbctype
 | 
			
		||||
 */
 | 
			
		||||
@MappedTypes(JSONArray.class)
 | 
			
		||||
@MappedJdbcTypes(JdbcType.VARCHAR)
 | 
			
		||||
public class ArrayJsonHandler extends BaseTypeHandler<JSONArray> {
 | 
			
		||||
    //设置非空参数
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setNonNullParameter(PreparedStatement ps, int i, JSONArray parameter, JdbcType jdbcType) throws SQLException {
 | 
			
		||||
        ps.setString(i, String.valueOf(parameter.toJSONString()));
 | 
			
		||||
    }
 | 
			
		||||
    //根据列名,获取可以为空的结果
 | 
			
		||||
    @Override
 | 
			
		||||
    public JSONArray getNullableResult(ResultSet rs, String columnName) throws SQLException {
 | 
			
		||||
        String sqlJson = rs.getString(columnName);
 | 
			
		||||
        if (null != sqlJson){
 | 
			
		||||
            return JSONArray.parseArray(sqlJson);
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
    //根据列索引,获取可以为空的结果
 | 
			
		||||
    @Override
 | 
			
		||||
    public JSONArray getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
 | 
			
		||||
        String sqlJson = rs.getString(columnIndex);
 | 
			
		||||
        if (null != sqlJson){
 | 
			
		||||
            return JSONArray.parseArray(sqlJson);
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
    @Override
 | 
			
		||||
    public JSONArray getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
 | 
			
		||||
        String sqlJson = cs.getString(columnIndex);
 | 
			
		||||
        if (null != sqlJson){
 | 
			
		||||
            return JSONArray.parseArray(sqlJson);
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,57 @@
 | 
			
		||||
package com.stdiet.custom.typehandler;
 | 
			
		||||
 
 | 
			
		||||
import com.alibaba.fastjson.JSONObject;
 | 
			
		||||
import org.apache.ibatis.type.BaseTypeHandler;
 | 
			
		||||
import org.apache.ibatis.type.JdbcType;
 | 
			
		||||
import org.apache.ibatis.type.MappedJdbcTypes;
 | 
			
		||||
import org.apache.ibatis.type.MappedTypes;
 | 
			
		||||
 
 | 
			
		||||
import java.sql.CallableStatement;
 | 
			
		||||
import java.sql.PreparedStatement;
 | 
			
		||||
import java.sql.ResultSet;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
 
 | 
			
		||||
/**
 | 
			
		||||
 * Created by lixio on 2019/3/28 15:44
 | 
			
		||||
 * @description 用以mysql中json格式的字段,进行转换的自定义转换器,转换为实体类的JSONObject属性
 | 
			
		||||
 * MappedTypes注解中的类代表此转换器可以自动转换为的java对象
 | 
			
		||||
 * MappedJdbcTypes注解中设置的是对应的jdbctype
 | 
			
		||||
 */
 | 
			
		||||
 
 | 
			
		||||
@MappedTypes(JSONObject.class)
 | 
			
		||||
@MappedJdbcTypes(JdbcType.VARCHAR)
 | 
			
		||||
public class ObjectJsonHandler extends BaseTypeHandler<JSONObject>{
 | 
			
		||||
 
 | 
			
		||||
    //设置非空参数
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setNonNullParameter(PreparedStatement ps, int i, JSONObject parameter, JdbcType jdbcType) throws SQLException {
 | 
			
		||||
        ps.setString(i, String.valueOf(parameter.toJSONString()));
 | 
			
		||||
    }
 | 
			
		||||
    //根据列名,获取可以为空的结果
 | 
			
		||||
    @Override
 | 
			
		||||
    public JSONObject getNullableResult(ResultSet rs, String columnName) throws SQLException {
 | 
			
		||||
        String sqlJson = rs.getString(columnName);
 | 
			
		||||
        if (null != sqlJson){
 | 
			
		||||
            return JSONObject.parseObject(sqlJson);
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
    //根据列索引,获取可以为空的结果
 | 
			
		||||
    @Override
 | 
			
		||||
    public JSONObject getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
 | 
			
		||||
        String sqlJson = rs.getString(columnIndex);
 | 
			
		||||
        if (null != sqlJson){
 | 
			
		||||
            return JSONObject.parseObject(sqlJson);
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
    @Override
 | 
			
		||||
    public JSONObject getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
 | 
			
		||||
        String sqlJson = cs.getString(columnIndex);
 | 
			
		||||
        if (null != sqlJson){
 | 
			
		||||
            return JSONObject.parseObject(sqlJson);
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user