spring学习前奏001
2014-04-02 19:49
302 查看
再次学习spring,万事开头难,那就找个pdf吧,下载了一个《精通spring》的电子书,能不能精通先不管,每次写简单的代码,也能有新的收获,开始贴程序。
根据文档,写了三个类,helloworld
总是永恒传奇的开始,呵呵。
publicclass HelloWorld {
/**
* @Title: getContent
* @Description: TODO(读取配置文件并且返回读取的属性值)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
public String getContent(){
HelloWorldStr hello = new HelloWorldStr("helloworld.properties");
String helloContent = hello.getContent();
return helloContent;
}
}
——————————————————————————————————————————————————
/**
* @ClassName: HelloWorldStr
* @Description: TODO(这里用一句话描述这个类的作用)
* @author huangbin
876301469@qq.com
* @date 2014-4-2 下午7:04:26
*
*/
public class HelloWorldStr {
privateString propertyFileName ;
publicHelloWorldStr(String propertyFileName) {
this.propertyFileName= propertyFileName;
}
/**
* @Title: getContent
* @Description: TODO(从配置文件中读取内容)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
public String getContent() {
String helloWorld = "";
Properties property = new Properties();
InputStream is = this.getClass().getClassLoader()
.getResourceAsStream(propertyFileName);
try {
property.load(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
helloWorld = property.getProperty("helloworld");
return helloWorld;
}
}
——————————————————————————————————————————————————
/**
* @ClassName: HelloWorldClient
* @Description: TODO(客户端调用)
* @author huangbin
876301469@qq.com
* @date 2014-4-2 下午7:28:02
*
*/
public class HelloWorldClient {
public static void main(String[] args) {
HelloWorld hello = new HelloWorld();
System.out.println(hello.getContent());
}
}
——————————————————————————————————————————————————
功能很简单,但是学会了从配置文件中读取配置属性,不必自诩几年编程经验,细节总是决定成败的,每次都有收获,下一篇将重构该功能会引出spring。
根据文档,写了三个类,helloworld
总是永恒传奇的开始,呵呵。
publicclass HelloWorld {
/**
* @Title: getContent
* @Description: TODO(读取配置文件并且返回读取的属性值)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
public String getContent(){
HelloWorldStr hello = new HelloWorldStr("helloworld.properties");
String helloContent = hello.getContent();
return helloContent;
}
}
——————————————————————————————————————————————————
/**
* @ClassName: HelloWorldStr
* @Description: TODO(这里用一句话描述这个类的作用)
* @author huangbin
876301469@qq.com
* @date 2014-4-2 下午7:04:26
*
*/
public class HelloWorldStr {
privateString propertyFileName ;
publicHelloWorldStr(String propertyFileName) {
this.propertyFileName= propertyFileName;
}
/**
* @Title: getContent
* @Description: TODO(从配置文件中读取内容)
* @param @return 设定文件
* @return String 返回类型
* @throws
*/
public String getContent() {
String helloWorld = "";
Properties property = new Properties();
InputStream is = this.getClass().getClassLoader()
.getResourceAsStream(propertyFileName);
try {
property.load(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
helloWorld = property.getProperty("helloworld");
return helloWorld;
}
}
——————————————————————————————————————————————————
/**
* @ClassName: HelloWorldClient
* @Description: TODO(客户端调用)
* @author huangbin
876301469@qq.com
* @date 2014-4-2 下午7:28:02
*
*/
public class HelloWorldClient {
public static void main(String[] args) {
HelloWorld hello = new HelloWorld();
System.out.println(hello.getContent());
}
}
——————————————————————————————————————————————————
功能很简单,但是学会了从配置文件中读取配置属性,不必自诩几年编程经验,细节总是决定成败的,每次都有收获,下一篇将重构该功能会引出spring。
相关文章推荐
- Spring boot学习笔记 001——初识Spring boot
- spring学习前奏002
- SPRING-BOOT学习记录001-第一个例子
- [原创]java WEB学习笔记104:Spring学习---AOP 前奏,通过一个问题引入动态代理
- spring学习前奏004
- extjs学习前奏---环境的搭建001
- spring boot 学习笔记(001) 新建Eclipse工程
- 37-001 spring学习
- Spring学习笔记001 - 依赖注入
- 【spring学习前奏】JavaBean内省Introspector以及BeanInfo
- spring学习前奏003
- Spring学习步骤-001
- Spring学习总结(12)——Druid连接池及监控在spring配置
- Spring Data Rest学习篇----Object Representation (实体对象展现)
- Spring学习【Spring概述】
- Spring再学习-声明式事务配置
- springMVC3学习(九)--redirect和forward跳转
- spring boot 学习(六)spring boot 各版本中使用 log4j2 记录日志
- SSH与SSM学习之Spring16——Spring中AOP之使用配置文件配置
- 近期学习Flex+Struts+Spring+Hibernate得心