静态代码块
public class DBUtils { private static String url=null; private static String username=null; private static String password=null; static{ try{ Properties dBJavaPro=FileUtils.getProByFileName("jdbc_moblie.properties"); url=dBJavaPro.getProperty("url").toString(); username=dBJavaPro.getProperty("username").toString(); password=dBJavaPro.getProperty("password").toString(); Class.forName("com.mysql.jdbc.Driver"); }catch(Exception e){ e.printStackTrace(); } } }
//构造函数 public class MemberAvivaSSoAction extends BaseAction { private String key; private String getMobileUrl; private Long roleId; private Long rankId; public MemberAvivaSSoAction() { this.key = (String) PropertyConfigurer.getContextProperty("aviva.cofco.key"); this.getMobileUrl = (String) PropertyConfigurer.getContextProperty("aviva.cofco.getMobileUrl"); this.roleId = Long.parseLong((String)PropertyConfigurer.getContextProperty("aviva.cofco.roleId")); this.rankId = Long.parseLong((String) PropertyConfigurer.getContextProperty("aviva.cofco.rankId")); }
无为而治