博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Spring MVC 基于AnnotationFormatterFactory接口实现自定义的规则
阅读量:3935 次
发布时间:2019-05-23

本文共 1885 字,大约阅读时间需要 6 分钟。

 

 

1、创建一个类来实现AnnotationFormatterFactory接口

 通过实现Formatter接口自定义自已的规则

 
PersonFrommId注解代码:
@Documented@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE})public @interface PersonFrommId {}
Person实体类代码:
package com.nf147.manage.demo_fromatter;import java.util.Date;public class Person {    private String name;    private String province;    private Date birthday;    private String gender;    public Person() {    }    public Person(String province, Date birthday, String gender) {        this.province = province;        this.birthday = birthday;        this.gender = gender;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }    public String getProvince() {        return province;    }    public void setProvince(String province) {        this.province = province;    }    public Date getBirthday() {        return birthday;    }    public void setBirthday(Date birthday) {        this.birthday = birthday;    }    public String getGender() {        return gender;    }    public void setGender(String gender) {        this.gender = gender;    }}
Controller层代码:
package com.nf147.manage.controller;import com.nf147.manage.demo_fromatter.Person;import com.nf147.manage.demo_fromatter.PersonFrommId;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;@RequestMapping("/ddd")@RestControllerpublic class DemoController {    @RequestMapping(method = RequestMethod.GET)    public Person home(@RequestParam(value = "id",required = false)@PersonFrommId Person person){        return person;    }}

 

 

 

 

 

 
 
 
 
 
 
 
 
posted @ 2018-12-05 11:27 阅读(...) 评论(...)

转载地址:http://sthgn.baihongyu.com/

你可能感兴趣的文章
find out the neighbour matrix of a mesh
查看>>
Operators and special characters in matlab
查看>>
As-Conformal-As-Possible Surface Registration
查看>>
qmake Variable Reference
查看>>
Lesson 2 Gradient Desent
查看>>
find border vertex
查看>>
matlab sliced variable
查看>>
create symbolic array
查看>>
TAUCS库的编译(vs2010)
查看>>
color vector using in plotting example points and lines between corresponding vertices
查看>>
mex 里面调用matlab函数
查看>>
matlab中cuda编程中分配grid和block dimension的时候的注意事项
查看>>
GPU CUDA and MEX Programming
查看>>
arrayfun用法
查看>>
矩阵积分
查看>>
optimization on macOS
查看>>
Template-Based 3D Model Fitting Using Dual-Domain Relaxation
查看>>
install libfreenect2 on ubuntu 16.04
查看>>
how to use automake to build files
查看>>
using matlab drawing line graph for latex
查看>>