当前位置: 首页>>代码示例>>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;未经允许,请勿转载。