欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springBoot 常用@注解标签

程序员文章站 2022-06-06 10:33:43
...

1.  @Service("/orgService")    

2.  @SuppressWarnings("unused")   忽略警告。

3.  @Value("${cloudDir}")    内容注入。

springBoot 常用@注解标签

 2. 接收数据类型为json对象or form表单数据类型时。

  a.  json

   controller层

/**
	 * 创建或修改查验任务
	 * @param task
	 * @return
	 */
	@RequestMapping(value = "/rest", params = "method=ciq.checktask.createtask")
	public ResMsg createTask(@RequestBody CheckTask task) {
		checkTaskService.createTask(this.getUserId(), task);
		return ResMsg.success();
	}

     service层 : 判断有无id,有id修改,无id新增。

    @Autowired
	private CheckTaskMapper checkTaskMapper;
	
	@Autowired
	private CheckTaskDetailMapper checkTaskDetailMapper;
	
	@Autowired
	private CheckTaskStepMapper checkTaskStepMapper;
	
	@Autowired
	private CrossOrderMapper crossOrderMapper;
	
	public int createTask(Long userId, CheckTask task) {
		int result = 0;
		if(task.getId() != null) {
			checkTaskMapper.updateByPrimaryKeySelective(task);
			//删除明细
			checkTaskDetailMapper.deleteByCheckTaskId(task.getId());
			//重新保存明细
			List<CheckTaskDetail> details = task.getDetails();
			for(int i=0; i<details.size(); i++) {
				CheckTaskDetail detail = details.get(i);
				detail.setCheckTaskId(task.getId());
				checkTaskDetailMapper.insert(detail);
			}
			//在步骤表中,记录修改通知的事件
			CheckTaskStep step = new CheckTaskStep();
			step.setCheckTaskId(task.getId());
			step.setUserId(userId);
			step.setStepTime(new Date());
			step.setStatus(CheckTask.CREATED_TASK);
			step.setStepName("修改通知");
			step.setRemark("修改记录");
			checkTaskStepMapper.insert(step);
		} else {
			CrossOrder order = crossOrderMapper.selectByPrimaryKey(task.getOrderId());
			task.setOrgId(order.getOrgId());
			task.setStatus(CheckTask.CREATED_TASK);//初始状态
			task.setCreateTime(new Date());
			checkTaskMapper.insert(task);
			//保存明细
			List<CheckTaskDetail> details = task.getDetails();
			for(int i=0; i<details.size(); i++) {
				CheckTaskDetail detail = details.get(i);
				detail.setCheckTaskId(task.getId());
				checkTaskDetailMapper.insert(detail);
			}
			//在步骤表中,记录创建通知的事件
			CheckTaskStep step = new CheckTaskStep();
			step.setCheckTaskId(task.getId());
			step.setUserId(userId);
			step.setStepTime(new Date());
			step.setStatus(CheckTask.CREATED_TASK);
			step.setStepName("创建通知");
			checkTaskStepMapper.insert(step);
		}
		return result;
	}

b.  form表单

     删除操作:

    /**
	 * 删除查验任务
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/rest", params = "method=ciq.checktask.remove")
	public ResMsg remove(Long id) {
		checkTaskService.remove(id);
		return ResMsg.success();
	}
    @Override
	public int remove(Object id) {
		CheckTask task = checkTaskMapper.selectByPrimaryKey(id);
		if(task != null && task.getStatus() != 0) {
			throw new BusinessException("{checkTask.status.cannotRemove}", "任务不允许删除");
		}
		return checkTaskMapper.deleteByPrimaryKey(id);
	}

 分页查询操作 :

    /**
	 * 查验任务处理列表
	 * @param pageIndex
	 * @param pageSize
	 * @param userId
	 * @param status
	 * @param eciqCode
	 * @return
	 */
	@RequestMapping(value = "/rest", params = "method=ciq.checktask.list")
	@ResponseBody
	public ResMsg list(Integer pageIndex, Integer pageSize, Long userId, String status, String eciqCode,
            String writeOffBillCode,String orderCode,String orgName,String createTime,String finishTime,String planTime) {
		
		//报检号eciqCode     核销号writeOffBillCode   订单编号 orderCode
		//申请单位 orgName   创建时间createTime    处理时间  finishTime
		Integer[] arrStatus = {0,1,2,3,4};
		 
		//创建任务、准备好,开始检查,完成检查,关闭任务
		if(hasRole("ciq_yunying")) {
			//看全部的
			PageList<CheckTask> page = checkTaskService.page(pageIndex, pageSize, userId, arrStatus, eciqCode,
					writeOffBillCode,orderCode,orgName,createTime,finishTime,planTime);
			return ResMsg.success(page);
		}
		if(hasRole("ciq_jianyiju")) {
			PageList<CheckTask> page = checkTaskService.page(pageIndex, pageSize, userId, arrStatus, eciqCode,
					writeOffBillCode,orderCode,orgName,createTime,finishTime,planTime);
			return ResMsg.success(page);
		}
		if (hasRole("ciq_chayanyuan")) {
			PageList<CheckTask> page = checkTaskService.page(pageIndex, pageSize, this.getUserId(), arrStatus, eciqCode,
					writeOffBillCode,orderCode,orgName,createTime,finishTime,planTime);
			return ResMsg.success(page);
		}
		return ResMsg.success(new PageList<CheckTask>());
	}
	@Override
	public PageList<CheckTask> page(Integer pageIndex, Integer pageSize, Long checkPersonelUserId, Integer[] arrStatus, String eciqCode,
			 String writeOffBillCode,String orderCode,String orgName,String createTime,String finishTime,String planTime) {
		
		Example exp = new Example(CheckTask.class);
		Criteria c = exp.createCriteria();
		
		//查验人员是自己
		if(checkPersonelUserId != null) {
			c.andEqualTo("checkPersonelUserId", checkPersonelUserId);
		}
		//状态
		if(arrStatus != null && arrStatus.length > 0) {
			c.andIn("status", Arrays.asList(arrStatus));
		}
		int[] status ={};
		//调用多条件查询的方法
		expBase(c, exp, null, status, eciqCode, writeOffBillCode, orderCode, orgName, createTime, finishTime, planTime);
		
		 
		return this.page(exp, pageIndex, pageSize);
	}