我想知道如何使用@return和@param来记录代码......?我有点猜测我会做类似的事情
@return(whatever the method is returning)
@param(parameters that the method is taking in)
Run Code Online (Sandbox Code Playgroud)
我之后是否需要提供更多说明?还有,有太多的文件吗?
我写了一个ParamConverterProvider和一个ParamConverter,以便让JAX-RS(Jersey)在HeaderParam中实例化一个枚举.转换器看起来像这样
@Provider
public class MyEnumParamConverterProvider implements ParamConverterProvider {
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
if (rawType.equals(MyEnum.class)) {
return (ParamConverter<T>) new MyEnumParamConverter();
}
return null;
}
private static class MyEnumParamConverter implements ParamConverter<MyEnum> {
@Override
public MyEnum fromString(String enum) {
return MyEnum.of(enum);
}
@Override
public String toString(MyEnum enum) {
return enum.toString();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是当没有发送Header时没有调用fromString方法,因为在方法类SingleValueExtractor中的Jersey代码org.glassfish.jersey.server.internal.inject.SingleValueExtractor.extract(MultivaluedMap<String, String>)上,第82行有一个代码检查参数值是否为null,如果它是!= null则fromString方法叫做.
public T extract(MultivaluedMap<String, String> parameters) {
String v = parameters.getFirst(getName());
if (v != null) {
try {
return fromString(v); …Run Code Online (Sandbox Code Playgroud) 关于访问jsp:param值,我有与此海报完全相同的基本问题;完全按照他的榜样对我不起作用。通过jsp:include传递的参数似乎没有显示在包含的文件中。我的设置有什么特别之处吗?
呼叫者:
<div>
<jsp:include page="../../../common/callee.jsp">
<jsp:param name="justinVar" value="primary" />
</jsp:include>
</div>
Run Code Online (Sandbox Code Playgroud)
callee.jsp:
<i>method 1: [</i><b><%= request.getParameter("justinVar") %></b><i>]</i>
<p/>
<i>method 2: [</i><b>${param.justinVar}</b><i>]</i>
<p/>
<i>method 3: [</i><b>${justinVar}</b><i>]</i>
<p/>
Run Code Online (Sandbox Code Playgroud)
最终输出:
method 1: [null]
method 2: []
method 3: []
Run Code Online (Sandbox Code Playgroud)
更新:以下解决方法确实起作用,这似乎是错误的,但是也许它起作用的事实揭示了一些不起作用的事实。
<c:set var="justinVar" value="justinVARisHere" scope="request" />
<jsp:include page="../../../common/callee.jsp" />
Run Code Online (Sandbox Code Playgroud) 这就是我绑定我的params的方式:
$Con = mysqli_connect(...);
$Statement = mysqli_stmt_init($Con);
mysqli_stmt_prepare($Statement,"select * from users where name=? and email=?");
mysqli_stmt_bind_param("s",$Username);
mysqli_stmt_bind_param("s",$Email); <-- it fails here
Run Code Online (Sandbox Code Playgroud)
但是当我用以下方法替换对mysqli_stmt_bind_param的2次调用时,它在其他情况下工作正常:
mysql_stmt_bind_param("ss",$Username,$Email)
Run Code Online (Sandbox Code Playgroud)
问题是我有一系列的参数; 我必须逐个绑定它们因为我不知道params的数量
现在我设法从数据库中获取值,我想指定更多我想要传递的内容.
从对下面的事件函数作出反应的选择框中,我想读出一个值(记录的uid)并将其传递给我的ajaxAction:
var uid;
$('#mySelectBox').change(function() {
arguments = $(this).attr('value');
var uri = '<f:uri.action arguments="{uid: '+uid+'}" action="ajax" controller="Mycontroller1" pageType="89657201" />';
jQuery.getJSON(uri, function(result) {
// do something
});
});
我用参数试了一下,不知道这是不是正确的方法.另外,正如Marcus Biesioroff建议的那样,我应该将我的JS保存到一个单独的文件中,但是我必须自己编写uri而不是Fluid方式,对吧?
我的ajaxAction看起来像这样:
public function ajaxAction($uid) {
$dataFromRepo = $this->myRepository->findByUid($uid);
$resultArray = array(
"field1" => $dataFromRepo->getField1(),
"field2" => $dataFromRepo->getField2(),
"field3" => $dataFromRepo->getField3(),
"field4" => $dataFromRepo->getField4(),
);
return json_encode($resultArray);
}
我确信uid没有正确传递,其他一切都有效.
在文件中aPage.xhtml,我有以下几行:
<ui:include rendered="#{not empty param.target}" src="#{param.target}.html" />
<ui:include rendered="#{empty param.target}" src="About.html" />
Run Code Online (Sandbox Code Playgroud)
通过以上的线路,我预计,当我去http://localhost:8080/beta/aPage.xhtml时,页面About.html会因为已有的param.targetIS null.但是,GlassFish抛出了以下异常:
java.io.FileNotFoundException: http://localhost:8080/beta/.html
Run Code Online (Sandbox Code Playgroud)
不知何故,param.target不被认为是null.
此外,我确实尝试使用==和!=运算符如下:
<ui:include rendered="#{param.target != null}" src="#{param.target}.html" />
<ui:include rendered="#{param.target == null}" src="About.html" />
Run Code Online (Sandbox Code Playgroud)
有趣的是,这一次,在GlassFish的控制台上,我没有看到任何异常抛出.但是,在浏览器上,仍会显示错误页面,但有例外java.io.FileNotFoundException.
如果你能告诉我为什么会这样,我应该做些什么来避免它,我将非常感激.
更新:
感谢Joop Eggen的提示,我终于用以下几行解决了这个问题:
<ui:param name="noTarget" value="About.html" />
<ui:param name="hasTarget" value="#{param.target}.html" />
<ui:include src="#{empty param.target? noTarget : hasTarget}" />
Run Code Online (Sandbox Code Playgroud)
最好的祝福
是否可以在准备好的mysqli语句中多次使用一个参数,而仅绑定一次?
像这样的东西
$stmt = $mysqli->prepare(SELECT * FROM user WHERE age BETWEEN ?1 - 2 AND ?1 + 2);
$stmt->bind_param('i', $myAge);
Run Code Online (Sandbox Code Playgroud)
我认为这是可能的PDO,但我不知道如何做到这一点mysqli。
我有一个像这样的网址:
site.co/asd#antani?id=9
Run Code Online (Sandbox Code Playgroud)
如何id动态地从此 url 获取值并在其更改时获取新值?
我尝试过:
console.log($routeParams);我进入Object {}了控制台
谢谢
我有一个模板,它是编辑某些元素的表单的一部分。要执行的操作因包含它的页面而异。所以我将 action 方法作为参数传递:
<ui:param name="option" value="#{someOptionBean}" />
...
<ui:include src="/WEB-INF/jsf/value-edit.xhtml">
<ui:param name="controllerParam" value="#{optionController}" />
<ui:param name="elementParam" value="#{option}" />
<ui:param name="actionParam" value="updateOption" />
</ui:include>
Run Code Online (Sandbox Code Playgroud)
或者:
<ui:param name="property" value="#{somePropertyBean}" />
...
<ui:include src="/WEB-INF/jsf/value-edit.xhtml">
<ui:param name="controllerParam" value="#{propertyController}" />
<ui:param name="elementParam" value="#{property}" />
<ui:param name="actionParam" value="updateProperty" />
</ui:include>
Run Code Online (Sandbox Code Playgroud)
并且value-edit.xhtml有一个命令按钮:
<p:commandButton value="Update" action="#{controllerParam[actionParam](elementParam)}" />
Run Code Online (Sandbox Code Playgroud)
到目前为止一切正常。
我的问题是现在操作方法没有相同数量的参数。他们是:
public void updateOption(Option option) { ... }
public void updateProperty(Item item, Prop property) { ... }
Run Code Online (Sandbox Code Playgroud)
所以我现在希望能够定义动作参数以具有以下内容:
<ui:param name="actionParam" value="updateOption(option)" />
<ui:param name="actionParam" value="updateProperty(item, property)" />
Run Code Online (Sandbox Code Playgroud)
或类似的东西: …
我试图在C#中编写一个Windows窗体应用程序,为指定用户输出AD属性.我希望它工作的方式是用户将一个值(用户名)输入到文本框中,该文本框作为参数传递给Powershell脚本,输出显示在表单中.
我用于创建参数和调用脚本的C#代码如下:
private string RunScript(string scriptText)
{
// create Powershell runspace
Runspace runspace = RunspaceFactory.CreateRunspace();
// open it
runspace.Open();
RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace);
// create a pipeline and feed it the script text
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(scriptText);
pipeline.Commands.Add(new Command("Set-ExecutionPolicy Unrestricted -Scope Process", true));
// "Get-Process" returns a collection of System.Diagnostics.Process instances.
pipeline.Commands.Add("Out-String");
//Create parameter and pass value to script
String username = textBox3.Text;
String scriptfile = @"c:\\scripts\\getpasswordexpirydate.ps1";
Command myCommand = new Command(scriptfile, false);
CommandParameter testParam = new CommandParameter("username", …Run Code Online (Sandbox Code Playgroud)