20170924

1. Springmvc中 JSR 303验证标准的实现

1.1 添加maven相关依赖

<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
    <dependency>
      <groupId>javax.validation</groupId>
      <artifactId>validation-api</artifactId>
      <version>2.0.0.Final</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
    <dependency>
      <groupId>org.hibernate.validator</groupId>
      <artifactId>hibernate-validator</artifactId>
      <version>6.0.2.Final</version>
    </dependency>

1.2 spring-mvc.xml配置中添加<mvc:annoation-driven/>标签

1.3 对应的属性上添加注解,如下,需要lastName字段不能为空

1.4 目标方法入参中对应的参数添加@Valid注解

1.5 方法入参中添加BindingResult,用于保存校验失败的信息

1.6 使用<form:errors>标签用于回显错误信息

1.7 代码运行结果如下

1.8 有个小坑:在方法入参Employee没有指定@ModelAttribute注解并指定value时,会以employee作为key去保存POJO对象以及errors相关信息,而在input页面的表单在没有指定modelattribute值时,默认以key=command读取POJO、Errors等相关信息,所以在Employee参数上添加@ModelAttribute注解并指定value=command。

2. 使用Srpingmvc返回JSON数据

2.1 添加maven依赖

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.9.1</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.9.1</version>
    </dependency>

   <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>2.9.1</version>
    </dependency>

2.2 在目标方法上添加@ResponseBody注解并以POJO对象或其集合的形式返回

2.3 结果如下:

用视频教程老师的话:简单到没有朋友

时间: 2024-08-29 09:37:12

20170924的相关文章

20170924 a20170924 a

\ ]20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a20170924 a2017092

校内模拟赛(20170924)

四校很丧,但是学长的题目更简单 lrb学长的题目为什么都要倒着切,不懂QAQ ----------------我是分割线---------------- T1:个人卫生综合征 每天BBS都要从家里经过城市中的一段路到学校刷五三.城市中一共有n个路口和m条双向道路,每条双向道路都连接着两个路口ai.bi且有一定的时间花费vi.BBS家编号为1,学校编号为n.今天,BBS由于个人卫生综合征导致他很迟才离开家,他想用膜法改变k条道路的长度使通过其的时间花费vi变为0.现在他问你改变道路长度之后他到学校

20170924习题

ex.32#循环和列表 the_count = [1,2,3,4,5]fruits = ['apples','oranges','pears','apricots']change = [1,'pennies',2,'dimes',3,'quarters'] #this first kind of for-loop goes through a list. for number in the_count: print ('this is count %d' %number) #same as ab

八校联考第二场(二试)(20170924)

NOIP 信心赛zzq题目名称函数排列数字串代码文件名func perm num输入文件名func.in perm.in num.in输出文件名func.out perm.out num.out时间限制1s 2s 2s空间限制512MB 512MB 512MB子任务分值10 20 30 40 10 20 20 10 40 20 30 30 20题目类型传统传统传统比较方式全文比较(忽略行末空格和文末换行)全文比较(忽略行末空格和文末换行)全文比较(忽略行末空格和文末换行)1. 题目难度和顺序大致

经济学相关资料20170924.词袋.books

经济学相关资料供内部教学使用,不得外传,看完删掉. 经济学概念词袋100.201709 经济本质和投资思考类.201709

Scrum Metting——市场调研组20170924

因市场探索需要,Teamer团队成立市场调研组具体架构如下 组长:周碧燕 组员:谭志坚.林细吉 一.Scrum Meeting照片 二.会议内容  ①确立调研方向 ②确立采访目标 ③制定采访流程与采访思路 ④研究产品核心需求 三.项目进度 ①预约陈科生老师采访(9月26日) ②预约陈玉菲老师采访(9月28日) ③预约郑创兴老师采访(9月28日) ④预约冯焯彬老师采访(9月28日) 四.心得体会 谭志坚(PM):三个小时头脑风暴,大家的脑袋都快运转不起来了.第一次讨论这种类型的问题有种不太适应的感

wget: unable to resolve host address “http”

[[email protected] ~]# wget www.baidu.com --2017-09-24 10:20:23-- http://www.baidu.com/ Resolving http... failed: Temporary failure in name resolution. wget: unable to resolve host address "http" 解决方案: [[email protected] ~]# vim /etc/resolv.conf

label 对齐

1 <label for="username">用户名</label> 2 <input type="text" id="username" name="username"/> 3 </p> 4 <p> 5 <label for="password">密码</label> 6 <input type="pas

java Date时间的各种转换方式和Mysql存时间类型字段的分析

一:各种Date之间的转换方法 public class TimeTest { public static void main(String[] args) { Date date = new Date(); // 一.获取当前系统时间和日期并格式化输出: SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 String dateTime = df.format(date); // For