當前位置: 首頁>>代碼示例>>Java>>正文


Java Validated類代碼示例

本文整理匯總了Java中org.springframework.validation.annotation.Validated的典型用法代碼示例。如果您正苦於以下問題:Java Validated類的具體用法?Java Validated怎麽用?Java Validated使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Validated類屬於org.springframework.validation.annotation包,在下文中一共展示了Validated類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getUserList

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
@GetMapping("/userListByPage.json")
    @ResponseBody
    @ApiOperation(value = "分頁查詢用戶列表", notes = "不傳分頁默認1頁15條")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "頁碼"),
            @ApiImplicitParam(name = "pageSize", value = "條數")
    })
    public JsonResponse getUserList(@Validated({Search.class}) UserQuery user,
                                    BindingResult bindingResult,
                                    PageKey pageKey)
            throws ValidateException {

        BindingResultUtil.validateResult(bindingResult);
        Page<Object> objects = PageHelper.startPage(pageKey.getPage(), pageKey.getPageSize(), true);
        UserExample example = new UserExample();
        example.createCriteria().andUserNameLike(StringUtil.turn2LikeStr(user.getName()));
        JsonResponse json = new JsonResponse();
        List<User> users = userMapper.selectByExample(example);
        json.putData("list", users);
        System.out.println("**********共有" + objects.getTotal() + "條數據*********");

//        redisTemplate.opsForList().rightPushAll("userList", users);
        return json;
    }
 
開發者ID:DomKing,項目名稱:webDemo,代碼行數:25,代碼來源:DemoController.java

示例2: add

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "新增任務信息", notes = "向係統中添加新的任務,任務必須是存儲過程,shell腳本,cmd腳本,可執行jar包,二進製文件中的一種")
public String add(@Validated TaskDefineEntity taskDefineEntity, BindingResult bindingResult, HttpServletResponse response, HttpServletRequest request) {
    // 校驗參數信息
    if (bindingResult.hasErrors()) {
        for (ObjectError m : bindingResult.getAllErrors()) {
            response.setStatus(421);
            return Hret.error(421, m.getDefaultMessage(), null);
        }
    }

    RetMsg retMsg = taskDefineService.add(parse(request));
    if (retMsg.checkCode()) {
        return Hret.success(retMsg);
    }
    response.setStatus(retMsg.getCode());
    return Hret.error(retMsg);
}
 
開發者ID:hzwy23,項目名稱:batch-scheduler,代碼行數:20,代碼來源:TaskDefineController.java

示例3: updatePassword

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
/**
 * 更新密碼
 * @param user
 * @param validResult
 * @return
 */
@Permission(value = {Privilege.USER, Privilege.ADMIN})
@RequestMapping(value = MappingURL.USER_PASSWORD_UPDATE, method = RequestMethod.PUT)
public ReturnPureNotifyApi updatePassword(
        @Validated({UserPassword.class}) User user,
        BindingResult validResult,
        HttpServletRequest request
        ){
    if (validResult.hasErrors()){
        throw new ValidationException(validResult.getFieldErrors());
    }else if (userService.find(user.getUserId()) == null){
        throw new NotExistedException("userId", user.getUserId());
    }
    TokenUser tokenUser = JavaWebTokenUtil.unsign(request.getHeader("appSecret"), TokenUser.class);
    assert tokenUser != null;
    //是管理員,為所欲為
    if (userService.find(tokenUser.getUserId()).getPrivilege() == Privilege.ADMIN.getCode()){
        userService.updatePassword(user);
        return new ReturnPureNotifyApi(ApiStatus.SUCCESS);
    }else if((tokenUser.getUserId() != user.getUserId())) {//不是管理員但是想更改別人的拋出異常
        throw new NoPermissionException();
    }
    userService.updatePassword(user);
    return new ReturnPureNotifyApi(ApiStatus.SUCCESS);
}
 
開發者ID:MasonQAQ,項目名稱:WeatherSystem,代碼行數:31,代碼來源:UserController.java

示例4: list

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
/**
 * @desc 分頁列表查詢
 *
 * @author liuliang
 *
 * @param pr
 * @return ComponentResult<Pager<MonitorSetBO>>
 */
@RequestMapping(value = "/list")
@ResponseBody
public ComponentResult<Pager<MonitorSetBO>> list(@Validated PageRequestBO pr,BindingResult br) {
	ComponentResult<Pager<MonitorSetBO>> componentResult = new ComponentResult<Pager<MonitorSetBO>>();
	//參數校驗
	Result validateResult = ValidatorUtil.getValidResult(br);
	if(ResultUtil.isfail(validateResult)) {
		return ResultUtil.copy(validateResult, componentResult);
	}
	//查詢
	try {
		int totalCount = monitorSetService.getCount();
		List<MonitorSetBO> records = monitorSetService.getDataList(pr.getPageIndex(),pr.getPageSize());
		
		componentResult.setData(new Pager<MonitorSetBO>(totalCount, records));
		return ResultUtil.success(componentResult);
	} catch (Exception e) {
		logger.error("分頁獲取數據異常,params:{}",pr.toString(),e);
	}
	//失敗返回
	return ResultUtil.fail(ErrorCode.QUERY_DB_ERROR,componentResult);
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:31,代碼來源:MonitorSetController.java

示例5: get

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
/**
 * @desc 查詢場景詳情
 *
 * @author liuliang
 *
 * @param sceneId 場景ID
 * @return ComponentResult<SceneDetailBO>
 */
@RequestMapping(value = "/get")
@ResponseBody
public ComponentResult<SceneDetailBO> get(@Validated(Groups.Query.class) SceneBO sceneBO,BindingResult br) {
	ComponentResult<SceneDetailBO> componentResult = new ComponentResult<SceneDetailBO>();
	//參數校驗
	Result validateResult = ValidatorUtil.getValidResult(br);
	if(ResultUtil.isfail(validateResult)) {
		return ResultUtil.copy(validateResult, componentResult);
	}
	//查詢
	try {
		Scene scene = sceneService.getScene(sceneBO.getSceneId());
		if(null != scene){
			String containLinkid = scene.getContainLinkid();
			List<Link> linkList = linkService.getLinkListByIds(containLinkid);
			
			componentResult.setData(new SceneDetailBO(scene, linkList));
			return ResultUtil.success(componentResult);
		}
	} catch (Exception e) {
		logger.error("查詢數據詳情異常,params:{}",sceneBO.toString(),e);
	}
	//失敗返回
	return ResultUtil.fail(ErrorCode.QUERY_DB_ERROR,componentResult);
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:34,代碼來源:SceneController.java

示例6: list

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
/**
 * @desc 分頁獲取鏈路數據
 *
 * @author liuliang
 *
 * @param request
 * @param response
 * @return ComponentResult<Pager<LinkBO>>
 */
@RequestMapping(value = "/list")
@ResponseBody
public ComponentResult<Pager<LinkBO>> list(@Validated PageRequestBO pr,BindingResult br) {
	ComponentResult<Pager<LinkBO>> componentResult = new ComponentResult<Pager<LinkBO>>();
	//參數校驗
	Result validateResult = ValidatorUtil.getValidResult(br);
	if(ResultUtil.isfail(validateResult)) {
		return ResultUtil.copy(validateResult, componentResult);
	}
	//查詢
	try {
		int totalCount = linkService.getLinkCount(pr.getFilterCondition());
		List<LinkBO> records = linkService.getLinkList(pr.getFilterCondition(),pr.getPageIndex(),pr.getPageSize());
		
		componentResult.setData(new Pager<LinkBO>(totalCount, records));
		return ResultUtil.success(componentResult);
	} catch (Exception e) {
		logger.error("分頁獲取數據異常,params:{}",pr.toString(),e);
	}
	//失敗返回
	return ResultUtil.fail(ErrorCode.QUERY_DB_ERROR,componentResult);
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:32,代碼來源:LinkController.java

示例7: add

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
/**
 * @desc 新增鏈路
 *
 * @author liuliang
 *
 * @param linkBO 鏈路BO
 * @return Result
 */
@RequestMapping(value = "/add")
@ResponseBody
public Result add(@Validated(Groups.Add.class) LinkBO linkBO,BindingResult br){
	Result result = new Result();
	//參數校驗
	Result validateResult = ValidatorUtil.getValidResult(br);
	if(ResultUtil.isfail(validateResult)) {
		return ResultUtil.copy(validateResult, result);
	}
	//新增
	try {
		int addResult = linkService.addLink(linkBO);
		if(0 < addResult) {
			return ResultUtil.success(result);
		}
	} catch(DuplicateKeyException de){
		logger.error("新增數據異常,鏈路名重複,params:{}",linkBO.toString(),de);
		return ResultUtil.fail(ErrorCode.UPDATE_DB_ERROR,"鏈路名已存在",result);
	} catch (Exception e) {
		logger.error("新增數據異常,params:{}",linkBO.toString(),e);
	}
	//返回失敗結果
	return ResultUtil.fail(ErrorCode.UPDATE_DB_ERROR,result);
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:33,代碼來源:LinkController.java

示例8: get

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
/**
 * @desc 查詢鏈路詳情
 *
 * @author liuliang
 *
 * @param id 鏈路ID
 * @return ComponentResult<Link>
 */
@RequestMapping(value = "/get")
@ResponseBody
public ComponentResult<Link> get(@Validated(Groups.Query.class) LinkBO linkBO,BindingResult br) {
	ComponentResult<Link> componentResult = new ComponentResult<Link>();
	//參數校驗
	Result validateResult = ValidatorUtil.getValidResult(br);
	if(ResultUtil.isfail(validateResult)) {
		return ResultUtil.copy(validateResult, componentResult);
	}
	//查詢
	try {
		Link link = linkService.getLink(linkBO.getLinkId());
		if(null != link) {
			componentResult.setData(link);
			return ResultUtil.success(componentResult);
		}
	} catch (Exception e) {
		logger.error("查詢數據詳情異常,params:{}",linkBO.toString(),e);
	}
	//失敗返回
	return ResultUtil.fail(ErrorCode.QUERY_DB_ERROR,componentResult);
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:31,代碼來源:LinkController.java

示例9: list

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
/**
 * @desc 分頁列表
 *
 * @author liuliang
 *
 * @param pr
 * @param br
 * @return
 */
@RequestMapping(value = "/list")
@ResponseBody
public ComponentResult<Pager<AutomaticTaskBO>> list(@Validated PageRequestBO pr,BindingResult br) {
	ComponentResult<Pager<AutomaticTaskBO>> componentResult = new ComponentResult<Pager<AutomaticTaskBO>>();
	//參數校驗
	Result validateResult = ValidatorUtil.getValidResult(br);
	if(ResultUtil.isfail(validateResult)) {
		return ResultUtil.copy(validateResult, componentResult);
	}
	//查詢
	try {
		int totalCount = automaticTaskService.getCount();
		List<AutomaticTaskBO> records = automaticTaskService.getDataList(pr.getPageIndex(),pr.getPageSize());

		componentResult.setData(new Pager<AutomaticTaskBO>(totalCount, records));
		return ResultUtil.success(componentResult);
	} catch (Exception e) {
		logger.error("分頁獲取數據異常,params:{}",pr.toString(),e);
	}
	//失敗返回
	return ResultUtil.fail(ErrorCode.QUERY_DB_ERROR,componentResult);
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:32,代碼來源:AutomaticTaskController.java

示例10: update

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
/**
 * @desc 更新
 *
 * @author liuliang
 *
 * @param automaticTaskBO
 * @param br
 * @return
 */
@RequestMapping(value = "/update")
@ResponseBody
public Result update(@Validated(Groups.Update.class) AutomaticTaskBO automaticTaskBO,BindingResult br) {
	Result result = new Result();
	//參數校驗
	Result validateResult = ValidatorUtil.getValidResult(br);
	if(ResultUtil.isfail(validateResult)) {
		return ResultUtil.copy(validateResult, result);
	}
	//更新
	try {
		int updateResult = automaticTaskService.update(automaticTaskBO);
		if (0 < updateResult) {
			// 同步定時任務
			this.syncAutomaticTask(automaticTaskBO, TaskSyncTypeEnum.UPDATE.value);
			return ResultUtil.success(result);
		}
	} catch (Exception e) {
		logger.error("更新數據異常,params:{}",automaticTaskBO.toString(),e);
	}
	//失敗返回
	return ResultUtil.fail(ErrorCode.UPDATE_DB_ERROR,result);
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:33,代碼來源:AutomaticTaskController.java

示例11: get

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
/**
 * @desc 查
 *
 * @author liuliang
 *
 * @param automaticTaskBO
 * @param br
 * @return
 */
@RequestMapping(value = "/get")
@ResponseBody
public ComponentResult<AutomaticTask> get(@Validated(Groups.Query.class) AutomaticTaskBO automaticTaskBO,BindingResult br) {
	ComponentResult<AutomaticTask> componentResult = new ComponentResult<AutomaticTask>();
	//參數校驗
	Result validateResult = ValidatorUtil.getValidResult(br);
	if(ResultUtil.isfail(validateResult)) {
		return ResultUtil.copy(validateResult, componentResult);
	}
	//查詢
	try {
		AutomaticTask automaticTask = automaticTaskService.getDataDetail(automaticTaskBO.getAutomaticTaskId());
		if(null != automaticTask) {
			componentResult.setData(automaticTask);
			return ResultUtil.success(componentResult);
		}
	} catch (Exception e) {
		logger.error("查詢數據詳情異常,params:{}",automaticTaskBO.toString(),e);
	}		
	//失敗返回
	return ResultUtil.fail(ErrorCode.QUERY_DB_ERROR,componentResult);
}
 
開發者ID:yunjiweidian,項目名稱:TITAN,代碼行數:32,代碼來源:AutomaticTaskController.java

示例12: doSubmitAction

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
@RequestMapping(method = RequestMethod.POST)
protected String doSubmitAction(@ModelAttribute("command") @Validated UserSettingsCommand command, BindingResult bindingResult, RedirectAttributes redirectAttributes) throws Exception {

    if(!bindingResult.hasErrors()) {
        if (command.isDeleteUser()) {
            deleteUser(command);
        } else if (command.isNewUser()) {
            createUser(command);
        } else {
            updateUser(command);
        }
        redirectAttributes.addFlashAttribute("settings_reload", true);
        redirectAttributes.addFlashAttribute("settings_toast", true);
    } else {
        redirectAttributes.addFlashAttribute("command", command);
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.command", bindingResult);
        redirectAttributes.addFlashAttribute("userIndex", getUserIndex(command));
    }

    return "redirect:userSettings.view";
}
 
開發者ID:airsonic,項目名稱:airsonic,代碼行數:22,代碼來源:UserSettingsController.java

示例13: addStudent

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
@RequestMapping(value = "/addStudent",method = RequestMethod.POST)
    public String addStudent(@ModelAttribute("student") @Validated Student student, BindingResult bindingResult,ModelMap model){
//        if(bindingResult.hasErrors()){
//            return "addStudent";
//        }
        System.out.println("id = "+student.getId());
        model.addAttribute("id",student.getId());
        model.addAttribute("name",student.getName());
        model.addAttribute("age",student.getAge());
        model.addAttribute("receivePaper",student.isReceivePaper());
        model.addAttribute("gender",student.getGender());
        model.addAttribute("color",student.getColor());
        model.addAttribute("city",student.getCity());
        model.addAttribute("tec",student.getTec());
        return "result";
    }
 
開發者ID:garyhu1,項目名稱:spring_mvc_demo,代碼行數:17,代碼來源:InputController.java

示例14: add

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
/**
 * 新增域
 */
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "新增域信息", notes = "添加新的域信息,新增的域默認授權給創建人")
@ApiImplicitParam(name = "domain_id", value = "域編碼", required = true, dataType = "String")
public String add(@Validated DomainEntity domainEntity, BindingResult bindingResult, HttpServletResponse response, HttpServletRequest request) {
    if (bindingResult.hasErrors()) {
        for (ObjectError m : bindingResult.getAllErrors()) {
            response.setStatus(421);
            return Hret.error(421, m.getDefaultMessage(), null);
        }
    }

    String userId = JwtService.getConnUser(request).getUserId();
    domainEntity.setDomainModifyUser(userId);
    domainEntity.setCreateUserId(userId);
    RetMsg retMsg = domainService.add(domainEntity);

    if (retMsg.checkCode()) {
        return Hret.success(retMsg);
    }

    response.setStatus(retMsg.getCode());
    return Hret.error(retMsg);
}
 
開發者ID:hzwy23,項目名稱:batch-scheduler,代碼行數:28,代碼來源:DomainController.java

示例15: update

import org.springframework.validation.annotation.Validated; //導入依賴的package包/類
@RequestMapping(method = RequestMethod.PUT)
@ResponseBody
public String update(@Validated TaskDefineEntity taskDefineEntity, BindingResult bindingResult, HttpServletResponse response, HttpServletRequest request) {
    if (bindingResult.hasErrors()) {
        for (ObjectError m : bindingResult.getAllErrors()) {
            response.setStatus(421);
            return Hret.error(421, m.getDefaultMessage(), null);
        }
    }

    RetMsg retMsg = taskDefineService.update(parse(request));
    if (!retMsg.checkCode()) {
        response.setStatus(retMsg.getCode());
        return Hret.error(retMsg);
    }
    return Hret.success(retMsg);
}
 
開發者ID:hzwy23,項目名稱:batch-scheduler,代碼行數:18,代碼來源:TaskDefineController.java


注:本文中的org.springframework.validation.annotation.Validated類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。