Action接口:
public interface Action {
public String execute(String str);
}
Action的两个实现
public class UpperAction implements Action {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String string) {
message = string;
}
public String execute(String str) {
return (getMessage() + str).toUpperCase();
}
}
public class LowerAction implements Action {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String string) {
message = string;
}
public String execute(String str) {
return (getMessage()+str).toLowerCase();
}
}
配置文件bean.xml
<beans>
<description>Spring Quick Startdescription>
<bean id="TheAction"
class="com.raykey.spring.qs.UpperAction">
<property name="message">
<value>HeLLovalue>
property>
bean>
beans>
(请确保配置bean.xml位于工作路径之下,注意工作路径并不等同于CLASSPATH ,eclipse的默认工作路径为项目根路径,也就是.project文件所在的目录,而默认输出目录/bin是项目CLASSPATH的一部分,并非工作路径。)
本文介绍了Spring中Action接口的使用,展示了UpperAction和LowerAction两个实现类,它们分别将字符串转换为大写和小写。配置文件bean.xml中定义了一个名为'TheAction'的bean,其class为UpperAction,并设置了message属性。注意配置文件的工作路径和CLASSPATH的区别。
&spm=1001.2101.3001.5002&articleId=25556983&d=1&t=3&u=77eeea3d952c4ff4afe41d4880d54934)

被折叠的 条评论
为什么被折叠?



