Java writes configuration information to the database (using reflection)

Source: Internet
Author: User
Tags reflection

Demo Source:

1. Package Com.fpx.pcs.prealert.process.xml.service.impl;

public class Cainiaopushmessageserviceimpl implements Icainiaopushmessageservice {

@Resource

Private Commonimpl Commonimpl;

@Override
Public Resultmessage Execute (string xml, String Msg_type, String Packagecarriertype, String countrycode) {

Cainiaocallbackconfig config=commonimpl.getconfig ("Cainiaocallbackconfig", cainiaocallbackconfig.class);

}

2.---cainiaocallbackconfig class---------------------

@data

public class Cainiaocallbackconfig implements Serializable{

Private static final long serialversionuid=1l;

Private String Conso3plcooperationcode;

Private String conso3plencryprdigest;

Private String Conso3plreturnurl;

}

3.getConfig notation

Public <T> T GetConfig (String configname,class<t> targetclass) {

List<sysparameterpo> Configs=getlistbyname (ConfigName);

if (Collectionutils.isempty (configs)) {

return null;

}

T T=null;

try{

t=targetclass.newinstance ();

for (Sysparameterpo config:configs) {

try{

Method Method=t.getclass (). GetMethod ("Set" +config.getcode (), string.class);

if (method!=null) {

Method.invoke (T,config.getvalue ());

}

catch (Exception e)

}

catch (Exception e)

{

}

}

}

catch (instantiationexception | illegeaccessexception e) {

E.printstatcktrace ();

}

catch (SecurityException e)

{

E.printstacktrace ();

}

}

Java writes configuration information to the database (using reflection)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.