Java表增删改查

//例如:日志表增删改查(表名jms_jc_apc_cancel_log)

1、domain文件夹新建 class → JmsJcApcCancelLog

 对应表结构get/set

@TableName(value = "jms_jc_apc_cancel_log")
public class JmsJcApcCancelLog {
	@TableId(value = "id",type = IdType.ASSIGN_ID) //主键

	private Long id;                //id bigint primary key,
	private String patient_id;      //patient_id varchar(12),
	private Integer times;          //times int,

	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getPatient_id() {
		return patient_id;
	}
	public void setPatient_id(String patient_id) {
		this.patient_id = patient_id;
	}
	public Integer getTimes() {
		return times;
	}
	public void setTimes(Integer times) {
		this.times = times;
	}
}

2、mapper文件夹新建 interface → JmsJcApcCancelLogMapper 

@Component
@Mapper
public interface JmsJcApcCancelLogMapper extends BaseMapper<JmsJcApcCancelLog> {

}

3、执行sql语句查询

查询函数:mapper文件夹新建 interface → ChisCustMapper

@Component
@Mapper
public interface ChisCustMapper {
    @Select("EXEC jms_getJcApcCancelList #{begin_time},#{end_time},#{apply_type},#{mz_zy_flag}")
    List<VoJcApcCancel> jms_getJcApcCancelList(@Param("begin_time")String begin_time, @Param("end_time")String end_time, @Param("apply_type")String apply_type, @Param("mz_zy_flag")String mz_zy_flag);
}

执行查询

List<VoJcApcCancel> cancelList = 
chisCustMapper.jms_getJcApcCancelList(begin_time,end_time,apply_type,mz_zy_flag);

4、插入

//【插入】
JmsJcApcCancelLog log= new JmsJcApcCancelLog();//new一个日志表对象
log.setOrder_sn(orderSn);
log.setChannel(channel);
log.setApply_type(applyType);
log.setCharge_no(chargeNo);
log.setExam_serial(examSerial);
log.setPatient_id(patientId);
log.setTimes(times);
log.setMz_zy_flag(mzZyFlag);
log.setCancel_result("0");
jmsJcApcCancelLogMapper.insert(log);

5、更新

//【更新】
//方法1
//该方法更新全表
log.setCancel_result(cancelResult);
log.setIn_log(inputXML);
log.setOut_log(outputXml);
jmsJcApcCancelLogMapper.updateById(log);
//方法2
//该方法只更新需要更新的字段
LambdaUpdateWrapper<JmsJcApcCancelLog> updateWrapper = Wrappers.lambdaUpdate();
updateWrapper.set(JmsJcApcCancelLog::getCancel_result,cancelResult); //成功失败标识
updateWrapper.set(JmsJcApcCancelLog::getIn_log,inputXML); //入参
updateWrapper.set(JmsJcApcCancelLog::getOut_log,outputXml); //出参
updateWrapper.eq(JmsJcApcCancelLog::getId,log.getId());
jmsJcApcCancelLogMapper.update(null,updateWrapper);

6、删除

//【删除】
//方法1
//单一条件主键删除
jmsJcApcCancelLogMapper.deleteById("此处写需要删除的id值即可");
//方法2
//多条件删除或联合主键删除
LambdaQueryWrapper<JmsJcApcCancelLog> queryWrapper = Wrappers.lambdaQuery();
updateWrapper.eq(JmsJcApcCancelLog::getId,"此处写需要删除的id值");
updateWrapper.eq(JmsJcApcCancelLog::getPatient_id,"此处写需要删除的patient_id值");
jmsJcApcCancelLogMapper.delete(queryWrapper);

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值