Action的类型

article/2025/8/22 5:20:48

 A、使用普通的类

  • 必须有public的execute且返回值为String的方法。

ActionType.java

复制代码
package com;public class ActionType_1 {public String execute(){System.out.println("我是Action类型1");return null;}
}
复制代码

 

  B、实现Actin接口

  • 实现com.opensymphony.xwork2.Action接口,并实现该接口中的execute()方法。
  • 在实际开发中,action类很少直接实现Action接口,通常都是从com.opensymphony.xwork2.ActionSupport类继承,ActionSupport实现了Action接口和其他一些可选的接口,提供了输入验证,错误信息存取,以及国际化的支持,选择从ActionSupport继承,可以简化action的定义。

  • Action接口中定义了一些常量和一个方法。

 

  C、继承ActionSupport类

  • 这个类里面封装了大量的方法,且实现了B中Action接口,
复制代码
package com;import com.opensymphony.xwork2.ActionSupport;public class ActionType_3 extends ActionSupport {@Overridepublic String execute() throws Exception {System.out.println("这是继承ActionSupport的类");return super.execute();}}
复制代码

 

 二、调用Action中的方法

  A、  使用method属性

示例:

ActionMethod_1.java:

复制代码
package method;import com.opensymphony.xwork2.ActionSupport;public class ActionMethod_1 extends ActionSupport {@Overridepublic String execute() throws Exception {System.out.println("执行默认execute方法");return super.execute();}public String add(){System.out.println("执行add方法");return NONE;}public String del(){System.out.println("执行del方法");return NONE;}public String list(){System.out.println("执行list方法");return NONE;}public String uptdate(){System.out.println("执行uptdate方法");return NONE;}
}
复制代码

假设Actionmethod_1这个Action中有4个方法(除execute外),如果我们要用method属性调用这些方法,则需要:

struts.xml

复制代码
    <package name="default" namespace="/" extends="struts-default"><action name="method_1"  class="method.ActionMethod_1"  method="add"></action><action name="method_2"  class="method.ActionMethod_1"  method="del"></action><action name="method_3"  class="method.ActionMethod_1"  method="uptdate"></action><action name="method_4"  class="method.ActionMethod_1"  method="list"></action></package>
复制代码

如配置,当地址栏URL=“工程名/method_1”时,执行method.ActionMethod_1类中的add方法;  当地址栏URL=“工程名/method_2”时,执行method.ActionMethod_1类中的adel方法,以此类推。

  • 缺点:如果某个类有很多方法的时候,那么配置起来很麻烦,代码非常多,一般适用于类方法特别少的情况下。

  B、  使用动态方法调用

  • 对以上示例优化:

 

ActionMethod_1.java:

 

复制代码
package method;import com.opensymphony.xwork2.ActionSupport;public class ActionMethod_1 extends ActionSupport {@Overridepublic String execute() throws Exception {System.out.println("执行默认execute方法");return super.execute();}public String add(){System.out.println("执行add方法2");return NONE;}public String del(){System.out.println("执行del方法2");return NONE;}public String list(){System.out.println("执行list方法2");return NONE;}public String uptdate(){System.out.println("执行uptdate方法2");return NONE;}
}
复制代码

struts.xml

复制代码
<struts><constant name="struts.enable.DynamicMethodInvocation" value="true" /><constant name="struts.devMode" value="true" /><package name="default" namespace="/" extends="struts-default">    <action name="method" class="method.ActionMethod_1"></action></package>
</struts>
复制代码
  •  注意: 使用动态方法调用,struts.enable.DynamicMethodInvocation 这个常量必须是true ;

index.jsp

复制代码
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<% String path=request.getContextPath(); %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body><a href="<%=path%>/method!add">执行add方法</a><a href="<%=path%>/method!del">执行del方法</a><a href="<%=path%>/method!uptdate">执行uptdate方法</a><a href="<%=path%>/method!list">执行list方法</a>
</body>
</html>
复制代码

解析: 当点击a标签时候,请求url中的!后跟的是方法名,<a href="<%=path%>/method!add">执行add方法</a>  即当点击这个标签时,执行action名为“method”中的add方法。其他的依次类推。 这种方法就避免了在struts.xml文件中配置过多,导致代码臃肿。  

注意的是:使用动态方法调用,struts.enable.DynamicMethodInvocation 这个常量必须是true ;

 

  C、  使用通配符方法(推荐使用)

 ActionMethod_1.java
复制代码
package method;import com.opensymphony.xwork2.ActionSupport;public class ActionMethod_1 extends ActionSupport {@Overridepublic String execute() throws Exception {System.out.println("执行默认execute方法");return super.execute();}public String add(){System.out.println("执行add方法3");return NONE;}public String del(){System.out.println("执行del方法3");return NONE;}public String list(){System.out.println("执行list方法3");return NONE;}public String uptdate(){System.out.println("执行uptdate方法3");return NONE;}
}
复制代码

idnex.jsp

复制代码
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<% String path=request.getContextPath(); %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body><a href="<%=path%>/method_add">执行add方法</a><a href="<%=path%>/method_del">执行del方法</a><a href="<%=path%>/method_uptdate">执行uptdate方法</a><a href="<%=path%>/method_list">执行list方法</a>
</body>
</html>
复制代码

struts.xml

复制代码
<struts><constant name="struts.enable.DynamicMethodInvocation" value="true" /><constant name="struts.devMode" value="true" /><package name="default" namespace="/" extends="struts-default">    <action name="method_*" class="method.ActionMethod_1" method="{1}"></action></package>
</struts>
复制代码
  •  解析:当点击<a href="<%=path%>/method_add">执行add方法</a> 这个标签的时候,请求url为"工程名/method_add",在命名空间为“/”的包下找到一个叫

“method_*”的Action,* 号表示任意字符(任意长度),即调用method.ActionMethod_1这个类,并调用method=“{1}” 这个方法,{1} 中的表示*表示的字符,在这个标签中*代表add,所以就调用了ActionMethod_1类中的add方法。

注意: 如果有多个通配符,

<action name="method_*_*" class="method.ActionMethod_1" method="{1}">   而标签为<a href="<%=path%>/method_exam_add">执行add方法</a>则调用的是第一个通配符匹配的字符即exam方法。

 

三、接收表单(用户请求)的值

 

   3.1  在struts中获取servlet的原生对象

  •   获取servlet原生对象的方式如下:

  A、  实现相应的接口,注入servlet对象

示例:

index.jsp

复制代码
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<% String path=request.getContextPath(); %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>  <a href="<%=path%>/servlet/obj">获取并测试servlet原生对象</a></body>
</html>
复制代码

struts.xml

复制代码
<struts><constant name="struts.enable.DynamicMethodInvocation" value="true" /><constant name="struts.devMode" value="true" /><package name="default" namespace="/servlet" extends="struts-default">    <action name="obj"  class="com.ServletObject"></action></package>
</struts>
复制代码

ServletObject.java

复制代码
package com;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.util.ServletContextAware;import com.opensymphony.xwork2.ActionSupport;public class ServletObject extends ActionSupport implements ServletRequestAware,ServletResponseAware,ServletContextAware{//定义servlet原生对象为成员变量,否则如果是局部变量生命周期太短。private ServletContext servletContext;private HttpServletResponse response;private HttpServletRequest request;private PrintWriter out;private HttpSession session;/*** 设置ServletContext*/public void setServletContext(ServletContext servletContext) {this.servletContext=servletContext;}/*** 设置ServletResponse,得到response之后就可由response得到PrintWriter对象*/public void setServletResponse(HttpServletResponse response) {this.response=response;if(response!=null){try {this.out=response.getWriter();} catch (IOException e) {e.printStackTrace();}}}/*** 设置ServletRequest,得到request之后就可由request得到HttpSession*/public void setServletRequest(HttpServletRequest request) {this.request=request;if(request!=null){this.session=request.getSession();}}public String execute(){    /*** 测试servlet原生对线是否真正获取可以使用*/System.out.println(this.request.getContextPath()); //获取工程路径
        System.out.println(this.session.getId()); //获取session的id
        System.out.println(this.servletContext.getRealPath("/index.jsp")); //获取/index.jsp的真实路径this.out.print("我是PrintWriter类的对象out");return NONE;}
}
复制代码
  • 本例只获取了5中servlet原生对象,但只实现了ServletRequestAware,ServletResponseAware,ServletContextAware三个接口,至于printWriter、httpsession对象,则分别由ServletResponseAware对象、ServletRequestAware对象来获取即可。
  • ServletContext.getRealPath()获取的是真实路径,即在硬盘上的路径(如C:\Users\Administrator\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\struts_project_2\index.jsp),而request.getContextPath()获得是工程路径(如/struts_project_2)。

 

  B、  使用struts提供的静态类来获取

 

复制代码
package com;import java.io.PrintWriter;import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class ServletObject extends ActionSupport {public String execute(){    try{HttpServletRequest request=ServletActionContext.getRequest();HttpServletResponse response=ServletActionContext.getResponse();ServletContext servletContext=ServletActionContext.getServletContext();PrintWriter out=response.getWriter();HttpSession session=request.getSession();/*** 测试servlet原生对线是否真正获取可以使用*/System.out.println(request.getContextPath()); //获取工程路径System.out.println(session.getId()); //获取session的id  System.out.println(servletContext.getRealPath("/index.jsp")); //获取/index.jsp的真实路径out.print("我是PrintWriter类的对象out");}catch(Exception e){e.printStackTrace();}return NONE;}
}
复制代码
  • ServletActionContext 这个静态类提供了Servlet原生对象的创建等。

 

  • 在Action中获取servlet原生对象的总结:

 一般来说用第一种方法来获取,但是这种方法每个Action都要写一大堆代码很麻烦,所以这里可以把这些servlet原生对象封装为一个抽象基类,其他Action要使用servlet原生对象的话就继承这个抽象类并实现抽象execute方法即可。

示例:

 BaseAction.java

复制代码
package com;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.util.ServletContextAware;public abstract class BaseAction implements ServletRequestAware,ServletResponseAware,ServletContextAware {HttpServletRequest request;HttpServletResponse response;ServletContext servletContext;HttpSession session;PrintWriter out;public void setServletContext(ServletContext servletContext) {this.servletContext=servletContext;}public void setServletResponse(HttpServletResponse response) {this.response=response;if(response!=null){try {this.out=response.getWriter();} catch (IOException e) {e.printStackTrace();}}}public void setServletRequest(HttpServletRequest request) {this.request=request;if(request!=null){this.session=request.getSession();}}abstract public String execute();}
复制代码

 

 

  3.2  获取请求参数中的值

 A、  使用servlet原生对象request来获取

  A1. 从GET请求中获取参数 :
  •      get把数据放在网址中,例如:http://www.abc.com/index.php?a=1&b=2 其中?a=1&b=2就是get数据,并且连http://www.abc.com/index.php长度限制在1024个字。

示例:

index.jsp:

复制代码
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<% String path=request.getContextPath(); %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body><a href="<%=path%>/request/getpost!get?userId=001&userName=用户名">用request原生对象来获取GET请求中的参数</a></body>
</html>
复制代码
  •   解析:“<%=path%>/request/getpost!get?userId=001&userName=用户名 ” 表示在“/request”这个命名空间中找到getpost这个对象,执行这个对象中的get方法,并

把参数userId=001和userName=用户名作为参数传过去。

 

struts.xml

复制代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts><constant name="struts.i18n.encoding" value="UTF-8"></constant><constant name="struts.enable.DynamicMethodInvocation" value="true" /><constant name="struts.devMode" value="true" /><package name="request" namespace="/request" extends="struts-default" ><action name="getpost" class="com.ActionRequest"></action></package>
</struts>
复制代码
ActionRequest.java
复制代码
package com;import java.io.UnsupportedEncodingException;public class ActionRequest  extends BaseAction{@Overridepublic String execute() {return null;}public String get() throws UnsupportedEncodingException{/*** 模拟GET请求*/String userId=request.getParameter("userId");  String userName=request.getParameter("userName");   userName=new String(userName.getBytes("ISO-8859-1"),"UTF-8");System.out.println("userId="+userId);System.out.println("userName="+userName);return null;}public String post(){/*** 模拟POST请求*///TODOreturn null;}}
复制代码
  • 解析: userName=new String(userName.getBytes("ISO-8859-1"),"UTF-8"); 如果没有这行代码,结果的userName值是乱码,尽管我们在struts.xml里设置了<constant name="struts.i18n.encoding" value="UTF-8"></constant> 但是还是乱码,就算再加个    request.setCharacterEncoding("utf-8");也是没用的依旧是乱码,可知
  • struts.i18n.encoding=UTF-8和request.setCharacterEncoding("utf-8"); 只针对POST请求有作用,对GET是无效的。
  • 对于GET请求乱码问题,可以用 userName=new String(userName.getBytes("ISO-8859-1"),"UTF-8");  这种方法来做,但是如果每个页面都这样做的话或者说需要转的参数比较多的话就很麻烦,可以用过滤器来解决。
  • 过滤器解决GETPOST参数乱码示例见(四)Decorator设计模式解决GET/POST请求的乱码问题

 

  A2.POST请求      
  •      post则是把数据放到http请求中,例如还是传输a=1&b=2,可是网址还是http://www.abc.com/index.php,比如表单的post提交,在网址上我们是看不到用户输入的数据的。

  •  示例请见(四)Decorator设计模式解决GET/POST请求的乱码问题

 B、  使用属性驱动来获取

  •  原则:控件的名称等于Action中成员变量名,并且属性都要有getset方法。
  • 示例一:

index.jsp

复制代码
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>以属性驱动来获取表单值<form action="request/shuxing!post_2" method="post" >用户名:<input type="text" name="userName" /> <br/>&nbsp;码:<input  type="password" name="passWd"/><br/>&nbsp;好:<input type="checkbox" name="like" value="篮球"/>篮球<input type="checkbox" name="like" value="足球"/>足球<input type="submit"  /></form></body>
</html>
复制代码

界面:

struts.xml

复制代码
<struts><constant name="struts.enable.DynamicMethodInvocation" value="true" /><constant name="struts.devMode" value="true" /><package name="default" namespace="/request" extends="struts-default"><action name="shuxing" class="action.AttrrbuteDriver"></action></package>
</struts>
复制代码
  • AttrrbuteDriver.java
复制代码
package action;import java.util.List;public class AttrrbuteDriver extends BaseAction{
/*** 以属性驱动的方式来获取表单中的值* 前提是: 1. 控件名(即表单元素名)与Action中的成员变量名要一致*       2.    Action中的成员变量要有getset方法*/        private String userName;    //获取表单元素名为userName的值,private String passWd;        //获取表单元素名为passWd的值private List<String> like;  //也可以用String[]来获取表单元素名为checkbox的值public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getPassWd() {return passWd;}public void setPassWd(String passWd) {this.passWd = passWd;}public List<String> getLike() {return like;}public void setLike(List<String> like) {this.like = like;}@Overridepublic String execute() {System.out.println("execute方法");return null;}public String post_2(){     System.out.println(userName);System.out.println(passWd);for(String likes:like){System.out.println(likes);}        return null;} 
}
复制代码

    如果一个表单元素有很多的时候,那么Action中定义的成员变量就会很多,代码会冗长,所以我们可以把其中一些成员变量封装到JavaBean里,具体如下:

  •  属性驱动优化示例:

index.jsp

复制代码
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body><h3>以属性驱动来获取表单值</h3><form action="request/shuxing!post_2" method="post" >用户名:<input type="text" name="userName" /> <br/>&nbsp;码:<input  type="password" name="passWd"/><br/>&nbsp;好:<input type="checkbox" name="like" value="篮球"/>篮球<input type="checkbox" name="like" value="足球"/>足球<h3>注册狗的信息</h3>dogId:<input type="text" name="dog.dogId" /> <br/>dogName:<input type="text" name="dog.dogName" /> <br/>dogColor:<input type="text" name="dog.dogColor" /> <br/><input type="submit"  /></form></body>
</html>
复制代码
  • 注意这里的 name="dog.dogId" 中的“dog.dogId”的写法,dog为Action中成员变量的引用,dogId为javaBean中的成员变量名。

struts.xml

复制代码
<struts><constant name="struts.enable.DynamicMethodInvocation" value="true" /><constant name="struts.devMode" value="true" /><package name="default" namespace="/request" extends="struts-default"><action name="shuxing" class="action.AttrrbuteDriver"></action></package>
</struts>
复制代码
AttrrbuteDriver.java
复制代码
package action;import java.util.List;import bean.DogBean;public class AttrrbuteDriver extends BaseAction{
/*** 以属性驱动的方式来获取表单中的值* 前提是: 1. 控件名(即表单元素名)与Action中的成员变量名要一致*       2.    Action中的成员变量要有getset方法*/        private String userName;    //获取表单元素名为userName的值,private String passWd;        //获取表单元素名为passWd的值private List<String> like;  //也可以用String[]来获取表单元素名为checkbox的值  private DogBean dog;     //DogBean是JavaBeanpublic DogBean getDog() {return dog;}public void setDog(DogBean dog) {this.dog = dog;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getPassWd() {return passWd;}public void setPassWd(String passWd) {this.passWd = passWd;}public List<String> getLike() {return like;}public void setLike(List<String> like) {this.like = like;}@Overridepublic String execute() {System.out.println("execute方法");return null;}public String post_2(){System.out.println(userName);System.out.println(passWd);for(String likes:like){System.out.println(likes);}System.out.println(dog.getDogName());System.out.println(dog.getDogId());System.out.println(dog.getDogColor());return null;}
}
复制代码
  • DogBean.java
复制代码
package bean;public class DogBean {private String dogId;private String dogName;private String dogColor;
public String getDogId() {return dogId;
}
public void setDogId(String dogId) {this.dogId = dogId;
}
public String getDogName() {return dogName;
}
public void setDogName(String dogName) {this.dogName = dogName;
}
public String getDogColor() {return dogColor;
}
public void setDogColor(String dogColor) {this.dogColor = dogColor;
}
}
复制代码

结果:

解析:  dogId:<input type="text" name="dog.dogId" /> 中的“dog.dogId”中的dog为Action类(本例中为AttrrbuteDriver类)的成员变量名即private DogBean dog;  而且dog成员变量也要有getset方法。“dog.dogId”中的dogId为JavaBean(本例中为DogBean)的成员变量dogId.

 


 

 C、  使用模型驱动来获取

  •  定义一个模型来接受表单中的数据,前提是Action类实现ModelDriven<类型>,并重写其中的getModel()方法,比如class Action_One ModelDriven<Dog>()  意思是这个Action接受Dog这个模型的数据。
  • 每个Action类只能实现一个ModelDriven<类型> 模型,也就是只能接受一个模型的数据。
  • 示例:

index.jsp

复制代码
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body><h3>以模型驱动来获取表单值</h3><form action="request/shuxing!post_2" method="post" >用户名:<input type="text" name="userName" /> <br/>&nbsp;码:<input  type="password" name="passWd"/><br/>&nbsp;好:<input type="checkbox" name="like" value="篮球"/>篮球<input type="checkbox" name="like" value="足球"/>足球<h3>注册狗的信息</h3>dogId:<input type="text" name="dogId" /> <br/>dogName:<input type="text" name="dogName" /> <br/>dogColor:<input type="text" name="dogColor" /> <br/><input type="submit"  /></form></body>
</html>
复制代码

界面:

struts.xml和DogBean.java与前一个例子一样,

复制代码
package action;import java.util.List;import com.opensymphony.xwork2.ModelDriven;import bean.DogBean;public class AttrrbuteDriver extends BaseAction implements ModelDriven<DogBean>{
/*** 模型驱动方法来获取表单元素值* 1. 实现ModelDriven<类型>,并重写其中的getModel()方法* 2. 本例中AttrrbuteDriver接受Dog这个模型的数据,且实现一个接口,即这个类只能接受一个数据模型,* 如果再加implements ModelDriven<DogBean>,ModelDriven<UserBean> * 这是错的,虽然平常来说语法是正确的。*/private String userName;    //获取表单元素名为userName的值,private String passWd;        //获取表单元素名为passWd的值private List<String> like;  //也可以用String[]来获取表单元素名为checkbooks的值private DogBean dog;public DogBean getModel() {this.dog=new DogBean();return dog;}public DogBean getDog() {return dog;}public void setDog(DogBean dog) {this.dog = dog;}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getPassWd() {return passWd;}public void setPassWd(String passWd) {this.passWd = passWd;}public List<String> getLike() {return like;}public void setLike(List<String> like) {this.like = like;}@Overridepublic String execute() {System.out.println("execute方法");return null;}public String post_2(){System.out.println(userName);System.out.println(passWd);for(String likes:like){System.out.println(likes);}System.out.println(dog.getDogName());System.out.println(dog.getDogId());System.out.println(dog.getDogColor());return null;}
}
复制代码

结果:



http://chatgpt.dhexx.cn/article/7jA1R76K.shtml

相关文章

ListActivity

ListActivity ListActivity中比较复杂的部分就是配置其Adapter&#xff0c;Adapter常用的有ArrayAdapter和SimpleAdapter。 首先我们先看一下简单的ArrayAdapter&#xff1a;ListActivity不同于普通Activity的地方是该Activity里边有一个ListView&#xff0c;该ListView绑定了A…

JAVA:Timer+actionListener

Timer类 •类描述&#xff1a; –它是一个按预定频率触发ActionEvent事件的源组件&#xff0c;利用它可以实现动态效果。 •构造方法&#xff1a; –Timer( int delay, ActionListener actionListener&#xff08;绑定监听器&#xff0c;开始后自己不断调用监听器的actionp…

actions的使用详解

actions的使用详解 为何要有actions环节 我们之前学了vuex状态管理&#xff0c;组件可以引用state&#xff0c;但是不能直接修改state,比如发送操作到actions&#xff0c;在此执行异步操作&#xff0c;然后再提交mutation来修改state.如果没有异步操作可以直接提交到mutation…

idea插件Material Theme主题设置方法

首先&#xff1a;如果要设置下图这种&#xff1a; 1. 先下载插件 2. 设置主题 3. 设置代码界面主题 4. 下载 Atom Material Icons插件

idea工具推荐几款好用的代码theme主题颜色

先去这个主题网站选择自己喜欢的主题http://color-themes.com/?viewindex 我个人比较喜欢这几款&#xff0c;你们要是喜欢其他主题的可以选择别的 点击下面的下下载按钮 跳转页面后点击下载 然后在我们的idea编辑器器中导入主题jar包找到我们下载的jar包然后点击ok 然后点击E…

Material Theme 主题插件 - Sublime 插件

1. 安装 Material Theme 主题插件 Material Theme主题、配色方案所占的区域 2. Material Theme 配色方案&#xff08;右侧区域&#xff09; 查看可用的配色方案 可选配色方案&#xff08;个人推荐&#xff1a;Material-Theme-Darker&#xff09; Darker 配色方案效果

android_基础_常见主题theme风格详解

本文出自门心叼龙的博客&#xff0c;转载请注明出处&#xff1a; https://blog.csdn.net/geduo_83/article/details/86560896 目录 1. 什么是Style&#xff0c;什么是Theme&#xff1f; 2. 在定义Theme的时候符号和&#xff1f;符号有何区别&#xff1f; 3. 怎么通过代码给…

iview 实现在theme主题中添加某一个新模块的主题颜色切换

背景&#xff1a;直接下载的iview-admin 1.3.1模板 1、iview 自带主题theme 主要有4个颜色组成 分别为 默认的蓝色&#xff0c;其他分别为红色&#xff0c;蓝色&#xff0c;洋红色&#xff1b;然后在根据菜单栏是否为黑色和白色的组合状态所以有8中组合的主题&#xff1b; 2、…

Android——Theme和Style-由浅入深,全面讲解

1、官方详细解读 样式和主题背景 | Android 开发者 | Android Developers 2、应用场景 类似web设计中css样式。将应用设计的细节与界面的结构和行为分开。 样式style &#xff1a;应用于 单个 View 的外观。样式可以指定字体颜色、字号、背景颜色等属性 主题theme&…

关于eclipse IDE安装Darkest Dark Theme主题插件

听说Darkest Dark Theme是现在最受欢迎的eclipse主题插件&#xff0c;于是我也来搞了一下。 Darkest Dark Theme官方网站(打开慢的要死&#xff0c;不知道是不是只有我会有这个问题。) https://marketplace.eclipse.org/content/darkest-dark-theme安装教程&#xff1a; 1.打开…

Vue Theme主题样式整理

为什么80%的码农都做不了架构师&#xff1f;>>> 一、ElementUI官方主题在线生成预览 https://elementui.github.io/theme-chalk-preview/#/zh-CN 使用步骤&#xff1a; 1.选择主题颜色&#xff0c;下载主题 包&#xff0c;然后解压 2.找到node_modules下的element-u…

Android Theme 常见主题风格详解

本文为自己多年来在Android实战开发过程中总结归纳的一些常见问题&#xff0c;现在分享出来希望对初学者有所帮助。 本文出自门心叼龙的博客&#xff0c;转载请注明出处&#xff1a; https://blog.csdn.net/geduo_83/article/details/86560896 目录 1. 什么是Style&…

Android自带的Theme主题图解

一、Manifest文件中: 从上图中我们可以看到在这个应用程序中我们的主题应用的是 AppTheme ,然后我们去看看 AppTheme 。 二、style.xml文件中: 这个文件是在应用工程中的: 然后又可以发现 AppTheme 主题样式是继承自 AppBaseTheme 主题样式的, 而 AppBaseTheme 主题样式又…

OpenWRT LUCI Theme主题定制

本人所写的博客都为开发之中遇到问题记录的随笔,主要是给自己积累些问题。免日后无印象,如有不当之处敬请指正(欢迎进扣群 24849632 探讨问题); 我们在github上先找一个合适的主题 https://github.com/search?q=luci+theme 比如我们以 rosywrt/luci-theme-rosy 为例 第…

Android的Theme主题切换

简单的Theme换肤功能 效果截图 1、定义属性 先定义几个需要改变的属性&#xff0c;例如&#xff1a; <!--换肤--><attr name"userNameColor" format"color" /><attr name"commonColor" format"color" /><…

Eclipse设置Theme主题颜色

设置Eclipse的代码编辑区背景为暗黑色系&#xff1a; 如需转载&#xff0c;请注明转载自&#xff1a;blog.csdn.net/it1988888 相关文件下载&#xff1a;http://guari.github.io/eclipse-ui-theme/ 方案一--下载颜色主题配置文件&#xff0c;离线导入配色方案的设置&#xf…

Jupyter lab Theme 主题更换

Jupyter lab Theme 主题更换 1. 打开Jupyter-lab2. 再拓展插件中搜索 “theme”3. 安装自己喜欢的主题4. 在Setting->JupyterLab Theme->选择"自己刚安装的主题"jupyterlab_miami_nights 主题jupyterlab_onedarkpro 主题 1. 打开Jupyter-lab 2. 再拓展插件中搜…

PySimpleGui theme主题使用

第一章 PySimpleGui theme主题使用 目录 系列文章目录 前言 一、theme是什么&#xff1f; 二、使用步骤 1.打印所有主题&#xff1a; 2.主题设置 3.更新主题的设置 总结 前言 通过设置主题&#xff0c;可快速设置GUI的颜色&#xff0c;节省自己设置UI的时间 一、theme是什么&a…

Hexo修改theme主题

学习目标 本文主要学习的内容如下&#xff1a; 如何去获取到 NexT 主题 如何去安装和配置 NexT 主题 设置菜单&#xff0c;如分类&#xff0c;标签&#xff0c;关于我等简单配置 获取开源的 Hexo 主题 在上节介绍如何快速去搭建 Hexo &#xff0c;最终展示的效果如下图所…

【Android开发基础】应用界面主题Theme使用方法

主题Theme就是用来设置界面UI风格&#xff0c;可以设置整个应用或者某个活动Activity的界面风格。在Android SDK中内置了下面的Theme&#xff0c;可以按标题栏Title Bar和状态栏Status Bar是否可见来分类&#xff1a; •android:theme"android:style/Theme.Dialog" …