当前位置: 首页 > news >正文

中山建网站哪家好wordpress数据库合并

中山建网站哪家好,wordpress数据库合并,seo推广工具,企业建设网站好处目录 一、引子 二、注解解析 RequestParam 一、要求形参名请求参数名,或者是请求实体类时(已有实体类),可以不需要加该注解 二、请求参数名!参数名时,需要写该注解RequestParam,其中 三、一名多值的情…

目录

一、引子

二、注解解析

@RequestParam

一、要求形参名=请求参数名,或者是请求实体类时(已有实体类),可以不需要加该注解

二、请求参数名!=参数名时,需要写该注解@RequestParam,其中

三、一名多值的情况使用list时,需要用到该注解@RequestParam,将集合add加入对应数据类型

@PathVariable

@RequestBody

@RequestHeader


一、引子

最近在写项目时,时不时会忘记或者漏写对应的参数注解,所以决定简单整理一下相关注解。

二、注解解析

@RequestParam

一、要求形参名=请求参数名,或者是请求实体类时(已有实体类),可以不需要加该注解

package com.atguigu.param;import com.atguigu.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;import java.util.List;@Controller
@RequestMapping("param")
public class ParamController {@RequestMapping("data")@ResponseBody//直接接收//要求请求参数名=形参名public String data(String name,int age){System.out.println("name = " + name + ", age = " + age);return "name = " + name + ", age = " + age;}@GetMapping("data3")@ResponseBody//使用实体对象接值public String data3(User user){System.out.println("user = " + user);return "user = " + user;}}

二、请求参数名!=参数名时,需要写该注解@RequestParam,其中

value=“指定请求参数名”

required=false,前端是否必须传递此参数,默认是必须,不传报错400

default=“1”,当非必须传递false,可以设默认值

package com.atguigu.param;import com.atguigu.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;import java.util.List;@Controller
@RequestMapping("param")
public class ParamController {@GetMapping("data1")@ResponseBody//注解指定public String data1(@RequestParam(value = "account") String username,@RequestParam(required = false,defaultValue = "1") int page){System.out.println("username = " + username + ", page = " + page);return "username = " + username + ", page = " + page;}}

三、一名多值的情况使用list时,需要用到该注解@RequestParam,将集合add加入对应数据类型

如果不加该注解,将会让hbs对应的一个字符串直接赋值给集合。

package com.atguigu.param;import com.atguigu.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;import java.util.List;@Controller
@RequestMapping("param")
public class ParamController {@GetMapping("data2")@ResponseBody//特殊值一名多值public String data2(@RequestParam List<String> hbs){System.out.println("hbs = " + hbs);return "hbs = " + hbs;}}

@PathVariable

路径传参时,必须用到@PathVariable

package com.atguigu.path;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;@Controller
@RequestMapping("path")
@ResponseBody
public class PathController {@GetMapping("{account}/{password}")public String login(@PathVariable String account,@PathVariable String password){System.out.println("account = " + account + ", password = " + password);return "account = " + account + ", password = " + password;}}

@RequestBody

前端传入json数据时需要用到@RequestBody,如@PostMapping,@DeleteMapping,@PutMapping中有时会用到

package com.atguigu.json;import com.atguigu.pojo.Person;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;@Controller
@RequestMapping("json")
@ResponseBody
public class JsonController {@PostMapping("data")public String data(@RequestBody Person person){System.out.println("person = " + person);return "person = " + person;}}

@RequestHeader

用于接收请求头

package com.atguigu.header;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;@Controller
@RequestMapping("header")
@ResponseBody
public class HeaderController {@RequestMapping ("data")public String data(@RequestHeader String host){System.out.println("host = " + host);return "host = " + host;}}

http://www.yayakq.cn/news/562816/

相关文章:

  • 为什么有点网站打不开微信网站流程
  • 牛商网 做的p2p网站大学生网页制作成品模板
  • 东莞优化网站关键词优化wordpress评论折叠
  • 做网站选用什么域名比较好创新驱动发展战略的内容
  • 营销型网站四大功能中国机械加工网加热炉节能
  • 天津专业网站制作流程优势国内ui网站
  • 领地网怎么编辑个人网站qq业务代理网站建设
  • 郴州网站seo优化wordpress注册直接显示密码
  • 两栏式网站wordpress手机调度插件
  • 西安网站建设kxccc邯郸市永年区做网站的公司
  • 班服定制网站百度地图开发网站
  • 购物网站每个模块主要功能最新seo新手教程
  • 怎么用网站做文案手表价格网站
  • 网站开发新技术探索网站规划与站点的建立实训报告
  • 有哪些做问卷调查的网站企业网站建设需要费用
  • 公司网站运营方案策划中国交通建设集团有限公司待遇
  • 网站在线沟通工具邯郸小学网站建设
  • 网站优化关键词网站设计公司发展
  • frontpage导入网站免费的销售管理系统
  • 定制型网站设计报价表wordpress一键关注
  • 企业网站建设外包服务合同长春老火车站图片
  • 润滑油网站怎样做效果更好杭州设计 公司 网站
  • 运动鞋的网站建设规划书怎么知道网站被k
  • 基因数据库网站开发价格python学习网站
  • 龙岗中心城有学网站建设新媒体营销和网络营销
  • 建设企业银行app做seo优化产品网站
  • 做音乐网站是不是侵权wordpress+万能搜索页
  • 请列举常见的网站推广方法wordpress search页面
  • 做电子板报的网站哪里有做旅游包车的网站
  • 软件技术专业介绍及就业方向seo北京优化