最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Spring?自定義propertyEditor的示例代碼

 更新時間:2022年12月13日 10:51:39   作者:Acaak  
這篇文章主要介紹了Spring?自定義propertyEditor的示例代碼,本文結(jié)合示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

User

package com.example.zylspringboot.selfEditor;

public class User {

    private String name;
    private Address address;
    private Integer age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", address=" + address +
                ", age=" + age +
                '}';
    }
}

Address

package com.example.zylspringboot.selfEditor;

public class Address {

    private String province;

    private String city;

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    @Override
    public String toString() {
        return "Address{" + "province='" + province + '\'' + ", city='" + city + '\'' + '}';
    }
}

SelfPropertyEditor

package com.example.zylspringboot.selfEditor;

import java.beans.PropertyEditorSupport;

public class SelfPropertyEditor extends PropertyEditorSupport {

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        String[] s = text.split("_");
        Address address = new Address();
        address.setCity(s[0]);
        address.setProvince(s[1]);
        super.setValue(address);
    }
}

AcaakPropertyRegistor

package com.example.zylspringboot.selfEditor;

import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;

public class AcaakPropertyRegistor implements PropertyEditorRegistrar {
    @Override
    public void registerCustomEditors(PropertyEditorRegistry propertyEditorRegistry) {
        propertyEditorRegistry.registerCustomEditor(Address.class,new SelfPropertyEditor());
    }
}

Xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">


    <bean id="user" class="com.example.zylspringboot.selfEditor.User">
        <property name="age" value="18"></property>
        <property name="name" value="Acaak"></property>
        <property name="address" value="廣東省_廣州市"></property>
    </bean>

    <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
        <property name="propertyEditorRegistrars">
            <list>
                <bean class="com.example.zylspringboot.selfEditor.AcaakPropertyRegistor"></bean>
            </list>
        </property>
    </bean>
	或
	<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
        <property name="customEditors">
            <map>
                <entry key="com.example.zylspringboot.selfEditor.Address">
                    <value>com.example.zylspringboot.selfEditor.SelfPropertyEditor</value>
                </entry>
            </map>
        </property>
    </bean>
</beans>

到此這篇關(guān)于Spring 自定義propertyEditor的文章就介紹到這了,更多相關(guān)Spring 自定義propertyEditor內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java中Mono類的一些基本方法和示例代碼

    Java中Mono類的一些基本方法和示例代碼

    在Java編程中,我們經(jīng)常會遇到需要創(chuàng)建單例(singleton)對象的情況,單例模式是一種常見的設(shè)計模式,它保證一個類只有一個實例,并提供一個全局訪問點,這篇文章主要給大家介紹了關(guān)于Java中Mono類的相關(guān)資料,需要的朋友可以參考下
    2024-07-07
  • Java實現(xiàn)簡單的掃雷小程序

    Java實現(xiàn)簡單的掃雷小程序

    這篇文章主要為大家詳細介紹了Java實現(xiàn)簡單的掃雷小程序,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-04-04
  • Java super關(guān)鍵字用法實戰(zhàn)案例分析

    Java super關(guān)鍵字用法實戰(zhàn)案例分析

    這篇文章主要介紹了Java super關(guān)鍵字用法,結(jié)合具體案例形式分析了java super關(guān)鍵字調(diào)用父類構(gòu)造方法、屬性及方法等相關(guān)操作技巧與注意事項,需要的朋友可以參考下
    2019-09-09
  • 一個applicationContext 加載錯誤導致的阻塞問題及解決方法

    一個applicationContext 加載錯誤導致的阻塞問題及解決方法

    這篇文章主要介紹了一個applicationContext 加載錯誤導致的阻塞問題及解決方法,需要的朋友可以參考下
    2018-11-11
  • 解決maven build 無反應,直接terminated的問題

    解決maven build 無反應,直接terminated的問題

    下面小編就為大家?guī)硪黄鉀Qmaven build 無反應,直接terminated的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • Java中Volatile的作用實例解析

    Java中Volatile的作用實例解析

    本篇文章給大家通過實例分享了Java中Volatile的作用,有興趣的朋友可以學習參考下。
    2018-07-07
  • IDEA的部署設(shè)置改為war exploded運行項目出錯問題

    IDEA的部署設(shè)置改為war exploded運行項目出錯問題

    在使用IDEA配置warexploded部署時,可能會遇到路徑問題或404錯誤,解決方法是進入Deployment設(shè)置,刪除Application content中的/marry_war_exploded,使其為空,然后重新運行項目即可,這是一種有效的解決策略,希望能幫助到遇到同樣問題的開發(fā)者
    2024-10-10
  • 深入淺析Java 虛擬線程

    深入淺析Java 虛擬線程

    Java21引入了虛擬線程,這是一種輕量級線程,適用于IO密集型的應用,可以極大提高應用的性能和吞吐量,虛擬線程是由傳統(tǒng)線程執(zhí)行的,由JVM控制上下文切換,創(chuàng)建和銷毀的開銷小,適用于高并發(fā)場景,本文介紹Java 虛擬線程的相關(guān)知識,感興趣的朋友跟隨小編一起看看吧
    2025-02-02
  • Mybatis查詢Sql結(jié)果未映射到對應得實體類上的問題解決

    Mybatis查詢Sql結(jié)果未映射到對應得實體類上的問題解決

    使用mybatis查詢表數(shù)據(jù)得時候,發(fā)現(xiàn)對應得實體類字段好多都是null,本文主要介紹了Mybatis查詢Sql結(jié)果未映射到對應得實體類上的問題解決,具有一定的參考價值,感興趣的可以了解一下
    2024-02-02
  • SpringBoot整合Web之CORS支持與配置類和 XML配置及注冊攔截器

    SpringBoot整合Web之CORS支持與配置類和 XML配置及注冊攔截器

    這篇文章主要介紹了SpringBoot整合Web開發(fā)中CORS支持與配置類和 XML配置及注冊攔截器的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-08-08

最新評論

邯郸市| 色达县| 连平县| 遵义市| 韩城市| 永顺县| 东丽区| 延安市| 磐安县| 漳平市| 永兴县| 科技| 绥中县| 麻江县| 德昌县| 临安市| 巴彦淖尔市| 安西县| 翁牛特旗| 清丰县| 米林县| 太谷县| 平和县| 综艺| 海城市| 嘉鱼县| 巴塘县| 宁夏| 新建县| 名山县| 株洲市| 富源县| 东源县| 屯门区| 肇东市| 陕西省| 定襄县| 丰顺县| 东乌珠穆沁旗| 花垣县| 会宁县|