首页 文章 精选 留言 我的

精选列表

搜索[图片标签],共10006篇文章
优秀的个人博客,低调大师

spring mvc的errors标签和validator用法

通过示例学习, 然后举一返三, 是最快的吸收知识的方式。 web.xml和springmvc-config.xml文件的内容同前面。 这一系列使用eclipse建立java项目时,选择动态web项目即可。 User.java package org.fkit.domain; import java.io.Serializable; public class User implements Serializable { /** * */ private static final long serialVersionUID = 1L; private String username; private String sex; private Integer age; public User() { super(); } public User(String username, String sex, Integer age) { super(); this.username = username; this.sex = sex; this.age = age; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } } UserValidator.java package org.fkit.validator; import org.fkit.domain.User; import org.springframework.validation.Errors; import org.springframework.validation.ValidationUtils; import org.springframework.validation.Validator; public class UserValidator implements Validator { @Override public boolean supports(Class<?> clazz) { return User.class.equals(clazz); } @Override public void validate(Object object, Errors errors) { ValidationUtils.rejectIfEmpty(errors, "username", null, "用户名不能为空"); ValidationUtils.rejectIfEmpty(errors, "sex", null, "性别不能为空"); ValidationUtils.rejectIfEmpty(errors, "age", null, "年龄不能为空"); } } UserController.java package org.fkit.controller; import org.fkit.domain.User; import org.fkit.validator.UserValidator; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.DataBinder; import org.springframework.validation.Errors; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @Controller public class UserController { @RequestMapping(value="/registerForm", method=RequestMethod.GET) public String registerForm(Model model) { User user = new User(); model.addAttribute("user", user); return "registerForm"; } @InitBinder public void initBinder(WebDataBinder binder) { binder.setValidator(new UserValidator()); } @RequestMapping(value="/register", method=RequestMethod.POST) public String register(@Validated User user, Errors errors) { if (errors.hasFieldErrors()) return "registerForm"; return "helloWorld"; } } registerForm.jsp <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <!DOCTYPE html PUBLIC "-//W3C/DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" > <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"> <title>welcome</title> </head> <body> <h3>注册页面</h3> <br> <form:form modelAttribute="user" action="register" method="post"> <table> <tr> <td><label>姓名: </label></td> <td><form:input path="username"/></td> <td><font color="red"><form:errors path="username" /></font></td> </tr> <tr> <td><label>性别: </label></td> <td><form:input path="sex"/></td> <td><font color="red"><form:errors path="sex" /></font></td> </tr> <tr> <td><label>年龄: </label></td> <td><form:input path="age"/></td> <td><font color="red"><form:errors path="age" /></font></td> </tr> <tr> <td><input id="submit" type="submit" value="register"></td> </tr> </table> </form:form> </body> </html> 测试:

优秀的个人博客,低调大师

CSS属性和HTML标签属性的区别

在DHTML和JAVASCRIPT编程中,都会用到大量STYLE或属性来设置页面效果和元素特性的。比如非常常用的ALIGN、SIZE、WIDTH、FONT-COLOR等,不过其中在CSS和DHTML属性的不同可能会导致一些设置出错或无效的时候。 1、 cursor:pointer!important;cursor:hand; 在TD等HTML元素中作为STYLE属性赋值可支持多种浏览器平台,但在CSS中不被支持。在属性中可以设置CURSOR多种取值,在CSS中也不被支持。 2、ALIGN在DHTML元素中用的比比皆是,且被大多数平台支持(DOM技术),但在CSS中只有TEXT-ALIGN来代替。即便是HR元素,在CSS中也须用TEXT-ALIGN来设置对齐(至少从多浏览器支持角度来说,因为MS IE会做很多不标准用法的兼容和容错,不予作为标准来考虑)。 3、在CSS中对属性取值必须不用双引号括起,否则会引起浏览器平台兼容问题(MS IE又支持了这种非标准用法)。在DHTML元素的属性取值时,双引号是可选的,当然是在不会引起岐义的前提 本文转自 dannyy1026 51CTO博客,原文链接: http://blog.51cto.com/dannyyuan/41208

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册