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

十大农业网站正规的家居行业网站开发

十大农业网站,正规的家居行业网站开发,东莞网站建设怎么收费,网站建设与制作软件1.javaee:意为java企业版,指java企业级开发的规范总和,包含13项技术规范 2.事实上服务器和客户端进行交互的过程中,有一个前端控制器在中间运作,这个控制器为DispatcherServlet,它负责将客户端请求的信息包…

1.javaee:意为java企业版,指java企业级开发的规范总和,包含13项技术规范

2.事实上服务器和客户端进行交互的过程中,有一个前端控制器在中间运作,这个控制器为DispatcherServlet,它负责将客户端请求的信息包装成HttpServletrequest对象,同时负责将服务器所传回的响应信息包装成HttpServletresponse对象.

3.获取请求参数的方式:

(1)原始方式:

package new_start.new_start4.controller;import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class ControllerHello {@RequestMapping("/simpleParam")public String simpleParam(HttpServletRequest request){String name = request.getParameter("name");String age = request.getParameter("age");int a = Integer.parseInt(age);System.out.println(name + "+" + age);return "ok";}
}

注意点:①getParameter的括号中必须加括号,表示字符串,且必须与请求参数的参数名一致;

②获取的是个字符串,需要自行进行转换;

(2)简单参数:

package new_start.new_start4.controller;import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class ControllerHello {@RequestMapping("/simpleParam")public String simpleParam(String name, Integer age){System.out.println(name + "+" + age);return "ok";}
}

第二种十分简洁,不需要进行类型转换;但要求形参名必须和请求参数名一致;

如果不一致,可以加上@RequestParam(name = “name”)注解:

package new_start.new_start4.controller;import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;@RestController
public class ControllerHello {@RequestMapping("/simpleParam")public String simpleParam(@RequestParam(name = "name") String username, Integer age){System.out.println( username + "+" + age);return "ok";}
}

同时该注解可以添加第二个参数:required;

默认为true,表示必须传入,否则报400错误,显示请求异常;

(3)实体对象参数:

这个需要创建一个实体类pojo,并用实体对象来接受请求参数,要求请求参数名必须对应实体类的属性名;同时有嵌套格式的话需要在请求时,进行加.的修饰:

例如:

package new_start.new_start4.controller;import jakarta.servlet.http.HttpServletRequest;
import new_start.new_start4.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;@RestController
public class ControllerHello {@RequestMapping("/pojo")public String pojo(User user){System.out.println(user);return "ok";}
}

(4)数组参数:

请求中只需要传值时使用同一个key值,同时这个key值等同于数组名即可;

package new_start.new_start4.controller;import jakarta.servlet.http.HttpServletRequest;
import new_start.new_start4.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.util.Arrays;@RestController
public class ControllerHello {@RequestMapping("/hobby")public String hobby(String[] hobby){System.out.println(Arrays.toString(hobby));return "ok";}
}

同时还可以用集合,只不过要加上@RequestParam:

package new_start.new_start4.controller;import jakarta.servlet.http.HttpServletRequest;
import new_start.new_start4.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.util.Arrays;
import java.util.List;@RestController
public class ControllerHello {@RequestMapping("/hobby")public String hobby(@RequestParam List<String> hobby){System.out.println(hobby);return "ok";}
}

(5)日期参数

(6)json参数:

通过json传递参数必须要用post请求方式,要把参数写在请求体中:同时用实体类接受,实体类的属性名和键名一致:但要注意形参名前要加@RequestBody

package new_start.new_start4.controller;import jakarta.servlet.http.HttpServletRequest;
import new_start.new_start4.pojo.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;import java.util.Arrays;
import java.util.List;@RestController
public class ControllerHello {@RequestMapping("/json")public String json(@RequestBody User user){System.out.println(user);return "ok";}
}(7)路径参数:注意要加@PathVariable,同时mapping路径映射要加{}来设定参数名
package new_start.new_start4.controller;import jakarta.servlet.http.HttpServletRequest;
import new_start.new_start4.pojo.User;
import org.springframework.web.bind.annotation.*;import java.util.Arrays;
import java.util.List;@RestController
public class ControllerHello {@RequestMapping("/path/{id}")public String json(@PathVariable Integer id){System.out.println(id);return "ok";}
}

http://www.dtcms.com/wzjs/794603.html

相关文章:

  • 上网建站查信息的网站有哪些
  • 企业网站推广案例鲁谷做网站的公司
  • 可以做网站的渠道中国最新军事新闻头条今天
  • 综合电子商务型企业网站门户网站建站方案
  • 受欢迎的建网站公司手机常用网站
  • 一般纳税人网站建设多少税率阿里指数在线查询
  • 南京模板建站全国有多少家展馆设计公司
  • 建站交流亚马逊电商平台
  • 网站建设 优势如何网站网站做代理
  • 戴尔网站建设目标百度快速收录权限
  • 行业网站建设详解wordpress默认的编辑器
  • 西北建设有限公司官方网站物流网站建设策划书的总结
  • 网站 开发流程网站可信度
  • 开发网站需要多少资金百度竞价排名案例
  • 网站上怎么做推广比较好呢佛山百度推广电话
  • 玉溪市住房和建设局公布网站拖拽式网站建设
  • 商城网站建设需求文档网站制作详细报价
  • 网站建设费的摊销期网站运营软件
  • 网站开发 设计文档数字广东网络建设公司
  • 邢台做网站的价格究竟多少钱?用php做美食网站有哪些
  • .tech域名的网站怎么不能安装wordpress
  • 网站后台多个管理员网站建设地基本流程
  • 网站开发亿码酷技术贴吧高级搜索
  • 企业网站建设劣势扁平化网站格局
  • php 怎么做 网站高端网站建设公司哪家服务好
  • 免费查看招标信息的网站云南网站优化
  • 免费公司建站旅游网站建设需求分析
  • 网页标准化对网站开发维护的好处网上项目外包
  • 上海做网站 公司 哪家好哪里有永久免费建站
  • 没有网站 淘宝客手机网站建设口碑好