该项目采用了mybatis框架,框架中包含model层,mapper层,service层和controller层。
- model层
用途:实体层,用于存放我们的实体类,与数据库中的属性值保持一致,实现set和get方法,之前提到的baseinfo就放在这里:
private Long id;
@ApiModelProperty(value = "试剂耗材编号")
private String code;
@ApiModelProperty(value = "试剂名称")
private String name;
@ApiModelProperty(value = "单位")
private String unit;
@ApiModelProperty(value = "规格型号")
private String specification;
@ApiModelProperty(value = "生产厂家")
private String manufacturerName;
@ApiModelProperty(value = "注册证号")
private String registrationNo;
@ApiModelProperty(value = "供货商 ID")
private String supplierId;
@ApiModelProperty(value = "供货商名")
private String supplierShortName;
@ApiModelProperty(value = "单价")
private Double price;
@ApiModelProperty(value = "储存温度: 常温,冷藏,冷冻")
private String stockType;
@ApiModelProperty(value = "过期预警时间阈值")
private Integer expirationLimit;
@ApiModelProperty(value = "低库存预警阈值")
private Integer stockLimit;
@ApiModelProperty(value = "开启有效期限")
private Integer useDayLimit;
private Date createTime;
private String createBy;
private Date updateTime;
private String updateBy;
@ApiModelProperty(value = "软删除标志: 0, 未删除, 1: 已删除")
private Byte deleteFlag;
private Date deleteTime;
private String deleteBy;
private static final long serialVersionUID = 1L;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getSpecification() {
return specification;
}
public void setSpecification(String specification) {
this.specification = specification;
}
public String getManufacturerName() {
return manufacturerName;
}
public void setManufacturerName(String manufacturerName) {
this.manufacturerName = manufacturerName;
}
public String getRegistrationNo() {
return registrationNo;
}
public void setRegistrationNo(String registrationNo) {
this.registrationNo = registrationNo;
}
public String getSupplierId() {
return supplierId;
}
public void setSupplierId(String supplierId) {
this.supplierId = supplierId;
}
public String getSupplierShortName() {
return supplierShortName;
}
public void setSupplierShortName(String supplierShortName) {
this.supplierShortName = supplierShortName;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getStockType() {
return stockType;
}
public void setStockType(String stockType) {
this.stockType = stockType;
}
public Integer getExpirationLimit() {
return expirationLimit;
}
public void setExpirationLimit(Integer expirationLimit) {
this.expirationLimit = expirationLimit;
}
public Integer getStockLimit() {
return stockLimit;
}
public void setStockLimit(Integer stockLimit) {
this.stockLimit = stockLimit;
}
public Integer getUseDayLimit() {
return useDayLimit;
}
public void setUseDayLimit(Integer useDayLimit) {
this.useDayLimit = useDayLimit;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getUpdateBy() {
return updateBy;
}
public void setUpdateBy(String updateBy) {
this.updateBy = updateBy;
}
public Byte getDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(Byte deleteFlag) {
this.deleteFlag = deleteFlag;
}
public Date getDeleteTime() {
return deleteTime;
}
public void setDeleteTime(Date deleteTime) {
this.deleteTime = deleteTime;
}
public String getDeleteBy() {
return deleteBy;
}
public void setDeleteBy(String deleteBy) {
this.deleteBy = deleteBy;
}
- mapper层
又名dao层。用途:对数据库进行数据持久化操作,它的方法语句是直接针对数据库操作的,主要实现一下增删改查操作。其中的方法主要与.xml文件内一一映射。如下:
public interface ReagentAdminMapper {
long countByExample(ReagentAdminExample example);
int deleteByExample(ReagentAdminExample example);
int deleteByPrimaryKey(Long id);
int insert(ReagentAdmin record);
int insertSelective(ReagentAdmin record);
List<ReagentAdmin> selectByExample(ReagentAdminExample example);
ReagentAdmin selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") ReagentAdmin record, @Param("example") ReagentAdminExample example);
int updateByExample(@Param("record") ReagentAdmin record, @Param("example") ReagentAdminExample example);
int updateByPrimaryKeySelective(ReagentAdmin record);
int updateByPrimaryKey(ReagentAdmin record);
}
以下是.xml文件中部分对应于.java文件内的方法:
<select id="selectByExample" parameterType="jp.co.nss.hrm.backend.model.ReagentAdminExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from reagent_admin
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from reagent_admin
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from reagent_admin
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="jp.co.nss.hrm.backend.model.ReagentAdminExample">
delete from reagent_admin
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="jp.co.nss.hrm.backend.model.ReagentAdmin">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into reagent_admin (username, password, branch,
supplier, group_name, phone,
true_name, icon, email,
address, nick_name, note,
create_time, login_time, status
)
values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{branch,jdbcType=VARCHAR},
#{supplier,jdbcType=VARCHAR}, #{groupName,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR},
#{trueName,jdbcType=VARCHAR}, #{icon,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR},
#{address,jdbcType=VARCHAR}, #{nickName,jdbcType=VARCHAR}, #{note,jdbcType=VARCHAR},
#{createTime,jdbcType=TIMESTAMP}, #{loginTime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}
)
</insert>
- service层
用途:给controller层的类提供接口进行调用。一般是把自己写的方法封装起来,具体的实现在serviceImpl中。 - controller层
用途:控制层,负责具体模块的业务流程控制,需要调用service逻辑设计层的接口来控制业务流程。controller通过接收前端传过来的参数进行业务操作,再将处理结果返回到前端。
以上两个层的具体代码在上一篇中都有提及,在此不做赘述。
mybits框架的层次划分及每一层的作用借鉴该博客:解析Java框架中各层的作用