对于jQuery缓存元素,$variable和variable之间的区别?感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍jquery缓存数据,并为您提供关于$VARIABLE和${VARIAB
对于jQuery缓存元素,$variable和variable之间的区别?感兴趣的读者,本文将会是一篇不错的选择,我们将详细介绍jquery 缓存数据,并为您提供关于$ VARIABLE和$ {VARIABLE}之间有什么区别、(*variable) 和 *&variable 有什么区别?、@PathVariable和@RequestParam的区别、@RequestParam与@PathVariable之间有什么区别的有用信息。
本文目录一览:- jQuery缓存元素,$variable和variable之间的区别?(jquery 缓存数据)
- $ VARIABLE和$ {VARIABLE}之间有什么区别
- (*variable) 和 *&variable 有什么区别?
- @PathVariable和@RequestParam的区别
- @RequestParam与@PathVariable之间有什么区别
jQuery缓存元素,$variable和variable之间的区别?(jquery 缓存数据)
这是一个例子:
var cached = $('.someElement'); var $cached = $('.someElement');
解决方法
缓存和$cached都是有效的Javascript变量:
var $message = 'Hello'; var message = 'Hello';
$variable语法经常使用to indicate the variable contains a jQuery object,而不是另一种类型(字符串,整数,DOM元素,…).这是一种匈牙利符号,但它只是程序员之间的惯例.没有任何Javascript或jQuery强加.
当人们谈论缓存jQuery变量时,他们意味着只进行一次查找:
//Like this: cached: search is done once. var clientSpan = $('#client'); clientSpan.hide(); clientSpan.show(); // ... //Not like this: uncached $('#client').hide(); $('#client').show(); // ...
$ VARIABLE和$ {VARIABLE}之间有什么区别
任何人都可以请给我一个解释,为什么一些Linux专家build议我们在Bash脚本中使用$ {VARIABLE}? 似乎没有任何区别。
不能使用任何环境variables
为什么不从bash脚本导出工作
程序使用过时的(不是当前的)envvariables值
shell和环境variables之间的区别
Debian $ PATHvariables的变化
假设你想打印$VARIABLE ,紧接着是"string"
echo "$VARIABLEstring" # tries to print the variable called VARIABLEstring echo "${VARIABLE}string" # prints $VARIABLE and then "string"
Bash还支持使用此语法的字符串操作 。
你可能想要这样做的一个原因是作为分隔符:
a=42 echo "${a}sdf" # 42sdf echo "$asdf" # prints nothing because there's no variable $asdf
这个功能通常用来保护周围字符的变量名。
$ var=foo
如果我们希望在$var的末尾连接一个字符串我们不能这样做:
$ echo $varbar $
因为这是试图使用一个新的变量$varbar 。
相反,我们需要将{} var {}括在{}中:
$ echo ${var}bar foobar
(*variable) 和 *&variable 有什么区别?
我正在使用 exercism.com 学习 go,并阅读教学大纲中推荐的文档和文章。
现在我在结构中并找到了下一个代码
package main import "fmt" type Employee struct { firstName, lastName string salary int fullTime bool } func main() { employee := &Employee{ firstName: "Walddys", lastName: "Dorrejo", salary: 1200, fullTime: true, } fmt.Println("firstName", (*employee).firstName) }
但是错误地,我输入了 fmt.println("firstname", *&employee.firstname),这给我带来了与之前在代码块中使用的相同结果。
我的问题是,使用这个指针是否存在不同或相同?
正确答案
&x 生成一个指向 x 的指针,而 *p 取消引用指针 p。因此 * 和 & 有效地相互抵消,例如 v := *&x 和 v := x 两个语句是相同的。
这意味着 *&employee.firstName 与 employee.firstName 相同。
其中 employee 是指向结构体的指针,而 firstName 是该结构体的字段,则表达式 employee.firstName 实际上是 (*employee).firstName 的简写。
这意味着 *&employee.firstName 也与 (*employee).firstName 相同。
请注意,您应该始终更喜欢使用速记符号。
以上就是(*variable) 和 *&variable 有什么区别?的详细内容,更多请关注php中文网其它相关文章!
@PathVariable和@RequestParam的区别
请求路径上有个id的变量值,可以通过@PathVariable来获取 @RequestMapping(value = "/page/{id}", method = RequestMethod.GET)
@RequestParam用来获得静态的URL请求入参 spring注解时action里用到。
简介:
handler method 参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类:(主要讲解常用类型)
A、处理requet uri 部分(这里指uri template中variable,不含queryString部分)的注解: @PathVariable;
B、处理request header部分的注解: @RequestHeader, @CookieValue;
C、处理request body部分的注解:@RequestParam, @RequestBody;
D、处理attribute类型是注解: @SessionAttributes, @ModelAttribute;
1、 @PathVariable
当使用@RequestMapping URI template 样式映射时, 即 someUrl/{paramId}, 这时的paramId可通过 @Pathvariable注解绑定它传过来的值到方法的参数上。
示例代码:
- @Controller
- @RequestMapping("/owners/{ownerId}")
- public class RelativePathUriTemplateController {
- @RequestMapping("/pets/{petId}")
- public void findPet(@PathVariable String ownerId, @PathVariable String petId, Model model) {
- // implementation omitted
- }
- }
上面代码把URI template 中变量 ownerId的值和petId的值,绑定到方法的参数上。若方法参数名称和需要绑定的uri template中变量名称不一致,需要在@PathVariable("name")指定uri template中的名称。
2、 @RequestHeader、@CookieValue
@RequestHeader 注解,可以把Request请求header部分的值绑定到方法的参数上。
示例代码:
这是一个Request 的header部分:
- Host localhost:8080
- Accept text/html,application/xhtml+xml,application/xml;q=0.9
- Accept-Language fr,en-gb;q=0.7,en;q=0.3
- Accept-Encoding gzip,deflate
- Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
- Keep-Alive 300
- @RequestMapping("/displayHeaderInfo.do")
- public void displayHeaderInfo(@RequestHeader("Accept-Encoding") String encoding,
- @RequestHeader("Keep-Alive") long keepAlive) {
- }
上面的代码,把request header部分的 Accept-Encoding的值,绑定到参数encoding上了, Keep-Alive header的值绑定到参数keepAlive上。
@CookieValue 可以把Request header中关于cookie的值绑定到方法的参数上。
例如有如下Cookie值:
- JSESSIONID=415A4AC178C59DACE0B2C9CA727CDD84
参数绑定的代码:
- @RequestMapping("/displayHeaderInfo.do")
- public void displayHeaderInfo(@CookieValue("JSESSIONID") String cookie) {
- }
即把JSESSIONID的值绑定到参数cookie上。
3、@RequestParam, @RequestBody
@RequestParam
A) 常用来处理简单类型的绑定,通过Request.getParameter() 获取的String可直接转换为简单类型的情况( String--> 简单类型的转换操作由ConversionService配置的转换器来完成);因为使用request.getParameter()方式获取参数,所以可以处理get 方式中queryString的值,也可以处理post方式中 body data的值;
B)用来处理Content-Type: 为application/x-www-form-urlencoded编码的内容,提交方式GET、POST;
C) 该注解有两个属性: value、required; value用来指定要传入值的id名称,required用来指示参数是否必须绑定;
示例代码:
- @Controller
- @RequestMapping("/pets")
- @SessionAttributes("pet")
- public class EditPetForm {
- @RequestMapping(method = RequestMethod.GET)
- public String setupForm(@RequestParam("petId") int petId, ModelMap model) {
- Pet pet = this.clinic.loadPet(petId);
- model.addAttribute("pet", pet);
- return "petForm";
- }
@RequestBody
该注解常用来处理Content-Type: 不是application/x-www-form-urlencoded编码的内容,例如application/json, application/xml等;
它是通过使用HandlerAdapter 配置的HttpMessageConverters来解析post data body,然后绑定到相应的bean上的。
因为配置有FormHttpMessageConverter,所以也可以用来处理application/x-www-form-urlencoded的内容,处理完的结果放在一个MultiValueMap<String, String>里,这种情况在某些特殊需求下使用,详情查看FormHttpMessageConverter api;
示例代码:
- @RequestMapping(value = "/something", method = RequestMethod.PUT)
- public void handle(@RequestBody String body, Writer writer) throws IOException {
- writer.write(body);
- }
4、@SessionAttributes, @ModelAttribute
@SessionAttributes:
该注解用来绑定HttpSession中的attribute对象的值,便于在方法中的参数里使用。
该注解有value、types两个属性,可以通过名字和类型指定要使用的attribute 对象;
示例代码:
- @Controller
- @RequestMapping("/editPet.do")
- @SessionAttributes("pet")
- public class EditPetForm {
- // ...
- }
@ModelAttribute
该注解有两个用法,一个是用于方法上,一个是用于参数上;
用于方法上时: 通常用来在处理@RequestMapping之前,为请求绑定需要从后台查询的model;
用于参数上时: 用来通过名称对应,把相应名称的值绑定到注解的参数bean上;要绑定的值来源于:
A) @SessionAttributes 启用的attribute 对象上;
B) @ModelAttribute 用于方法上时指定的model对象;
C) 上述两种情况都没有时,new一个需要绑定的bean对象,然后把request中按名称对应的方式把值绑定到bean中。
用到方法上@ModelAttribute的示例代码:
- // Add one attribute
- // The return value of the method is added to the model under the name "account"
- // You can customize the name via @ModelAttribute("myAccount")
- @ModelAttribute
- public Account addAccount(@RequestParam String number) {
- return accountManager.findAccount(number);
- }
- 这种方式实际的效果就是在调用@RequestMapping的方法之前,为request对象的model里put(“account”, Account);
用在参数上的@ModelAttribute示例代码:
- @RequestMapping(value="/owners/{ownerId}/pets/{petId}/edit", method = RequestMethod.POST)
- public String processSubmit(@ModelAttribute Pet pet) {
- }
首先查询 @SessionAttributes有无绑定的Pet对象,若没有则查询@ModelAttribute方法层面上是否绑定了Pet对象,若没有则将URI template中的值按对应的名称绑定到Pet对象的各属性上。
@RequestParam与@PathVariable之间有什么区别
@RequestParam
和@PathVariable
处理特殊字符之间有什么区别?
+
被@RequestParam
空间接受。
在的情况下@PathVariable
,+
被接受为+
。
答案1
小编典典@PathVariable
是要从URI(Spring称为URI模板)中获取一些占位符@RequestParam
也是要从URI中获取参数—请参见Spring Reference第16.3.3.3章,使用@RequestParam将请求参数绑定到方法参数
如果该网址http://localhost:8080/MyApp/user/1234/invoices?date=12-05-2013
在2013年12月5日获得了用户1234的发票,则控制器方法如下所示:
@RequestMapping(value="/user/{userId}/invoices", method = RequestMethod.GET)public List<Invoice> listUsersInvoices( @PathVariable("userId") int user, @RequestParam(value = "date", required = false) Date dateOrNull) { ...}
同样,请求参数可以是可选的,从Spring 4.3.3开始,路径变量也可以是可选的。但是请注意,这可能会更改URL路径层次结构并引入请求映射冲突。例如,是否/user/invoices
提供nullID为“发票”的用户发票或有关用户的详细信息?
关于jQuery缓存元素,$variable和variable之间的区别?和jquery 缓存数据的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于$ VARIABLE和$ {VARIABLE}之间有什么区别、(*variable) 和 *&variable 有什么区别?、@PathVariable和@RequestParam的区别、@RequestParam与@PathVariable之间有什么区别等相关知识的信息别忘了在本站进行查找喔。
本文标签: