我用这个:
import { HttpParams } from '@angular/common/http';
let params = new HttpParams();
params.append('newOrdNum','123');
Run Code Online (Sandbox Code Playgroud)
但这不起作用,我不会在网址中附加param.有什么建议吗?
我正在使用FOSRestBundle,并且想知道是否可以使用注释验证空查询参数?
例如打电话时:/comments/1因为这两个抛出一个异常dealId,并source查询参数尚未设置.
但是,/comments/1?dealId=1&source=即使该source值未设置并且与注释中概述的正则表达式不匹配,调用也可以.
控制器功能:
/**
* Get a single comment.
*
* @Annotations\QueryParam(name="dealId", requirements="\d+", strict=true, description="The deal the comments belong to.")
* @Annotations\QueryParam(name="source", requirements="(forum|blog)", strict=true, description="The source of the comments.")
*
* @Annotations\View()
*
* @Annotations\Get("/comments/{id}", requirements={"id" = "\d+"})
*
*/
public function getCommentAction(Request $request, ParamFetcherInterface $paramFetcher, $id)
{
$dealId = $paramFetcher->get('dealId');
$source = $paramFetcher->get('source');
// TODO: Implement
return [ 'id' => $id, 'dealId' => $dealId, 'source' => $source ]; …Run Code Online (Sandbox Code Playgroud) 我的版本 9 中有一个名为blog的页面nextjs。
Next为我的页面创建一个路由/博客。现在我想让这些路由映射到同一个博客页面,从而映射到博客组件:
1. /blog/cat1/gold
2. /blog/cat2/silver
3. /blog/cat3/bronze
Run Code Online (Sandbox Code Playgroud)
实际上,我想query parameters在路线中使用它们,但我不想遵循以下格式:
1. /blog?cat=cat1&color=gold
2. /blog?cat=cat2&color=silver
3. /blog?cat=cat3&color=bronze
Run Code Online (Sandbox Code Playgroud)
我使用过,next/router asPath但它完全是客户端,通过重新加载它返回404!
在nextjs 9动态路由中提供了这可能对我有帮助,但问题是我只想拥有一个组件和不同的路由。
你有什么想法?
我有一个类似的URL www.example.com/store/,它通向商店页面
当用户点击折扣链接时,它会添加参数?discount=foo,因此我的链接如下所示:www.example.com/store/?discount=foo.
一切都很实用.但是在这种情况下在查询字符串之前使用正斜杠是不好的做法吗?
我有一个Map<String, List<Object>>.
如何将其转换为Stream,Entry<String, Object>以便构建连接查询String?
q1 a, b
q2 c, d
Run Code Online (Sandbox Code Playgroud)
成
q1=a&q1=b&q2=c&q2=d
Run Code Online (Sandbox Code Playgroud)
我现在正在这样做.
if (params != null && !params.isEmpty()) {
final boolean[] flag = new boolean[1];
params.forEach((n, vs) -> {
vs.forEach(v -> {
builder.append(flag[0] ? '&' : '?')
.append(n)
.append('=')
.append(v);
if (!flag[0]) {
flag[0] = true;
}
});
});
}
Run Code Online (Sandbox Code Playgroud) Angular 是否可以检测查询参数是否已更改?我有一个处理 2 个查询参数的组件,并根据你附带的参数设置一些变量 true 或 false。问题是如果我在我的组件上使用 queryparameter 1 qp 可以更改为第二个参数而不离开组件,在这种情况下我需要设置不同的变量。那么我该如何检测呢?这甚至可能吗?
我认为使用REST Web服务的一个主要特征和原因是使用路径参数而不是查询参数.但是许多公开可用的REST Web服务使用查询参数.
我认为查询参数不应该在REST Web服务中使用我错了吗?是否有关于不在REST Web服务中使用查询参数的建议或规则?
所有Google Translate查询参数的含义是什么?
client:t
sl:auto
tl:sk
hl:sk //language of the interface (default:en, you can try xx-bork or xx-hacker)
dt:bd
dt:ex
dt:ld
dt:md
dt:qc
dt:rw
dt:rm
dt:ss
dt:t
dt:at
dt:sw
ie:UTF-8 // encoding of the input (default: utf-8)
oe:UTF-8 // encoding of the output, the results (default: utf-8)
otf:1
srcrom:1
ssel:3
tsel:0
q:translate // query, what you type in the search box
Run Code Online (Sandbox Code Playgroud)
我已经发现了其中一些.
在Angular 4中搜索关于各种类型的路由的多个线程/问题之后,我无法解决将queryParams传递给Angular 4路由的问题.
传递到网址时
http://localhost/search;x=y
Run Code Online (Sandbox Code Playgroud)
通过模板[queryParams] = {x:'y'}
<a [routerLink]="/search" [queryParams]="{x: 'y'}">Navigate</a>
Run Code Online (Sandbox Code Playgroud)
或在组件类中
this._router.navigate(['/search'], { queryParams: {x: 'y'} });
Run Code Online (Sandbox Code Playgroud)
结果是路由器抛出匹配错误:
Error: Cannot match any routes. URL Segment: 'search%3Fparam1%3Dtest1%26param2%3Dtest2'
Run Code Online (Sandbox Code Playgroud)
当将enableTracing设置为true时,我可以看到导航对可疑字符进行编码,这很可能是它无法匹配的原因.
我需要处理包含queryParams的URL并解析它们以进行api调用,因此必须在必需或可选的参数上使用查询参数路由.
有没有人有类似的问题,如果有的话,编码根源(ahem.)问题的原因是什么?
一旦我进行查询参数更改,我不确定为什么它显示默认路由.这种问题有更好的方法吗?也许我不应该使用查询参数?开放接受教育!
版本"反应":"^ 16.2.0","react-dom":"^ 16.2.0","react-router":"^ 4.2.0","react-router-dom":"^ 4.2. 2" ,
测试用例 https://codepen.io/adamchenwei/pen/YeJBxY?editors=0011
重现的步骤单击主页 - >步骤1
预期行为转到步骤1以及步骤2呈现正确的dom
实际行为为空,页面上没有任何呈现
// For this demo, we are using the UMD build of react-router-dom
const {
BrowserRouter,
Switch,
Route,
Link
} = ReactRouterDOM
const {
Component,
} = React;
const Router = BrowserRouter;
const Step1View = () => (
<div>
<h1> Step 1</h1>
</div>
)
const Step2View = () => (
<div>
<h1> Step 2</h1>
</div>
)
class Home extends Component {
constructor(props) {
super(props);
console.log('-!!!')
this.state …Run Code Online (Sandbox Code Playgroud) javascript query-parameters reactjs react-router react-router-v4
query-parameters ×10
angular ×3
react-router ×2
reactjs ×2
java ×1
java-8 ×1
java-stream ×1
javascript ×1
next.js ×1
php ×1
rest ×1
routing ×1
symfony ×1
url ×1
url-encoding ×1
web-services ×1