开发过程中的一些小经验

1:mybatis和vue字段的映射关系

1.1:看标签是resultType(resultType=“com.uinfor.wms.mat.domain.MatProductionTask”)还是resultMap(resultMap=“MatProductionTaskResult”)
若是resultType则字段写成驼峰命名(materialCode),同时保证字段存在实体类中,若是resultMap则字段写成material_code。注意:resulMap这样写得保证
中存在对应的映射字段,不然也是需要写成驼峰。

1.2:若存在多个字段则使用@Param(“materialProductionTask”)注解

2:sql

下面展示一些常用sql以及sql技能。

// orcale查找重复数据
select 
	* 
from 
	user a
where 
	(a.userCode,a.userName) 
in  
	(select userCode,userName from user group by userCode,userName having count(*) > 1);
// orcale查找重复数据
select 
	* 
from 
	user a
where 
	(a.userCode,a.userName) 
in  
	(select userCode,userName from user group by userCode,userName having count(*) > 1);
修改表名(把A表的名字改为B表)
RENAME TABLE A TO B;
RENAME TABLE A TO B;
添加字段(在unit字段后添加一个task_category 字段)
alter table wms_boot_nistart.mat_preparation Add column task_category varchar(255) AFTER unit;
alter table wms_boot_nistart.mat_preparation Add column task_category varchar(255) AFTER unit;
字段增加注释
alter table wms_boot_nistart.mat_preparation_execution modify column remarks4 varchar(255) comment '仓库名称';
alter table wms_boot_nistart.mat_preparation_execution modify column remarks4 varchar(255) comment '仓库名称';

分页查询
mysql直接使用limit即可,orcale比较麻烦。
orcale使用rownum,以下是两种实现方法:

select * from (select rownum no,a.* from emp a) where no between (pageNo-1)*pageSize+1 and pageNo*pageSize;
select * from emp where rownum between (pageNo-1)*pageSize+1 and pageNo*pageSize;

union和union all区别
union会对查询出来的结果进行去重,而union all不会对查询的结果去重,最好是使用union all,因为性能更好。

如果sql字段为空,依然还想要使用模糊查询

where ifnull(si.location_code,'DF4A0102') not like '%BL%'
having用法

过滤条件中使用了聚合函数,则必须用having代替where,having必须使用在groupby后面

select e.department_id ,max(e.salary)
from employees e
group by e.department_id
having max(e.salary)>10000 ;

3:一些其他的小细节

3.1:时间只展示了年月日,不展示时分秒
@JsonFormat(pattern = “yyyy-MM-dd HH:mm:ss”)

4:java 两个时间的比较

public static void main(String[] args) throws ParseException {
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
       Date today = new Date();
        System.out.println("today"+today);//todayFri Mar 17 09:58:40 CST 2023
       String endDate = sdf.format(today);
        System.out.println("endDate"+endDate);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(sdf.parse(endDate));
        calendar.add(Calendar.DATE,-30);
        Date time = calendar.getTime();
        System.out.println("time"+time);
        String format = sdf.format(time);
        System.out.println("format"+format);
        if (time.before(today)){
            System.out.println("true");
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值