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

优质的常州网站建设手机推广app

优质的常州网站建设,手机推广app,微信网页版下载,动画制作软件电脑版目录 详细参考day05 web请求 1、BS架构流程 2、RequestParam注解 完成参数名和形参的映射 3、controller接收json对象,使用RequestBody注解 4、PathVariable注解传递路径参数 5、ResponseBody(return 响应数据) RestController源码 6、统一响…

目录

详细参考day05 web请求

1、BS架构流程

2、@RequestParam注解 完成参数名和形参的映射

3、controller接收json对象,使用@RequestBody注解

4、@PathVariable注解传递路径参数

5、@ResponseBody(return 响应数据) 

      @RestController源码

6、统一响应结果

7、分层解耦

8、IOC和DI

控制反转代码示例:

IOC四类注解:

DI:@Autowired自动装配

@Primary @Qualifier @Resource


详细参考day05 web请求

1、BS架构流程

2、@RequestParam注解 完成参数名和形参的映射

 

3、controller接收json对象,使用@RequestBody注解

  4、@PathVariable注解传递路径参数

就是在@RequestMapping中加参数名比如{id}

5、@ResponseBody(return 响应数据) 

@RestController源码

6、统一响应结果

每个方法的返回值 从return  string/arr[]/student ------》 变成 return Result.success(list);  

//响应统一格式的结果
@RequestMapping("/getAddr")
public Result getAddr(){
Address addr = new Address();
addr.setProvince("广东");
addr.setCity("深圳");
return Result.success(addr);
}
public class Result {private Integer code;//响应码,1 代表成功; 0 代表失败private String msg; //响应码 描述字符串private Object data; //返回的数据public Result() { }public Result(Integer code, String msg, Object data) {this.code = code;this.msg = msg;this.data = data;}public Integer getCode() {return code;}public void setCode(Integer code) {this.code = code;}public String getMsg() {return msg;}public void setMsg(String msg) {this.msg = msg;}public Object getData() {return data;}public void setData(Object data) {this.data = data;}//增删改 成功响应(不需要给前端返回数据)public static Result success(){return new Result(1,"success",null);}//查询 成功响应(把查询结果做为返回数据响应给前端)public static Result success(Object data){return new Result(1,"success",data);}//失败响应public static Result error(String msg){return new Result(0,msg,null);}}

7、分层解耦

分层就是分成了controller层、service层,dao层

controller层负责:接收前端发送的请求,对请求进行处理,并响应数据(调用service层

service层:处理具体的业务逻辑(调用dao层

dao层负责:负责数据的访问操作,包含数据的增、删、改、查

service层和dao层都是面向接口编程的,目的是解耦(进一步解耦使用 控制反转和依赖注入)。

首先会定义一个接口层,然后再去实现这个接口。

        接口定义业务规则(比如需要哪些方法,需要哪些数据)

        实现类负责实现具体的业务逻辑 



我们发现在上面controller中我们定义的是一个service接口,然后new的是一个接口的实现类,赋值给接口,这是面向接口编程。但若是我们更换了业务逻辑,想要换一个实现类,如下所示,此时我们就要去修改controller中的代码,非常的不方便,所以我们要使用ioc和di解耦。

8、IOC和DI

IOC:叫做控制反转,核心就是我们不用手写代码创建对象,而是交给IOC容器创建

DI:叫做依赖注入,就是说代码运行需要什么对象时,我们不去创建,而是让IOC容器自己提供

IOC创建,管理的对象,叫做bean对象。

控制反转代码示例:

IOC四类注解:

IOC 容器中, 每一个Bean都有一个属于自己的名字 ,可以通过注解的 value 属性指定 bean 的名字。如果没有指定, 默认为类名首字母小写
使用四大注解声明的bean,要想生效,还需要被组件扫描注解@ComponentScan扫描
@ComponentScan注解虽然没有显式配置,但是实际上已经包含在了引导类声明注解
@SpringBootApplication 中, 默认扫描的范围是SpringBoot启动类所在包及其子包

DI:@Autowired自动装配

@Autowired 注解,默认是按照 类型 进行自动装配的(去IOC容器中找某个类型的对象,然后完成注入操作)
controller层需要service对象,就在代码内使用该注解,并定义一个service接口。
同dao。

@Primary @Qualifier @Resource

比如一个接口的两个实现类,由于自动装配找的接口对象,不使用额外注解就会报错。

@Primary 注解使用在接口的实现类中,service

@Qualifier使用在 调用者一级,比如controller,且必须和@Autowired一起使用,根据名字去找

@Resource注解和@Autowired注解是同级别的,只不过有区别


文章转载自:
http://paragon.bbrf.cn
http://acetify.bbrf.cn
http://rancheria.bbrf.cn
http://armada.bbrf.cn
http://bridle.bbrf.cn
http://gamboge.bbrf.cn
http://papalist.bbrf.cn
http://pedunculate.bbrf.cn
http://latah.bbrf.cn
http://dismission.bbrf.cn
http://pariahdom.bbrf.cn
http://whirry.bbrf.cn
http://cheerfulness.bbrf.cn
http://viewphone.bbrf.cn
http://unforfeitable.bbrf.cn
http://bakery.bbrf.cn
http://noctilucent.bbrf.cn
http://subshrub.bbrf.cn
http://pyrotechnical.bbrf.cn
http://metalline.bbrf.cn
http://ambilateral.bbrf.cn
http://trisodium.bbrf.cn
http://pvm.bbrf.cn
http://unclench.bbrf.cn
http://doctorand.bbrf.cn
http://cloacae.bbrf.cn
http://olfactometer.bbrf.cn
http://pungi.bbrf.cn
http://finlander.bbrf.cn
http://pictorially.bbrf.cn
http://agio.bbrf.cn
http://bickiron.bbrf.cn
http://expostulate.bbrf.cn
http://specialise.bbrf.cn
http://unpresented.bbrf.cn
http://aplasia.bbrf.cn
http://refectioner.bbrf.cn
http://carrottop.bbrf.cn
http://hexahedron.bbrf.cn
http://innocuous.bbrf.cn
http://finlet.bbrf.cn
http://setup.bbrf.cn
http://cytovirin.bbrf.cn
http://buses.bbrf.cn
http://lazybed.bbrf.cn
http://seafarer.bbrf.cn
http://sardanapalian.bbrf.cn
http://spirality.bbrf.cn
http://dirge.bbrf.cn
http://berliozian.bbrf.cn
http://longitude.bbrf.cn
http://marisat.bbrf.cn
http://boreas.bbrf.cn
http://sinogram.bbrf.cn
http://glimmery.bbrf.cn
http://trublemaker.bbrf.cn
http://handmaiden.bbrf.cn
http://catchy.bbrf.cn
http://cranioscopy.bbrf.cn
http://link.bbrf.cn
http://largamente.bbrf.cn
http://tyro.bbrf.cn
http://retiree.bbrf.cn
http://embryonal.bbrf.cn
http://mne.bbrf.cn
http://arsenotherapy.bbrf.cn
http://kneepad.bbrf.cn
http://elbowy.bbrf.cn
http://unsc.bbrf.cn
http://pleiotropic.bbrf.cn
http://quinate.bbrf.cn
http://randomize.bbrf.cn
http://olio.bbrf.cn
http://kation.bbrf.cn
http://unsolder.bbrf.cn
http://spadger.bbrf.cn
http://pile.bbrf.cn
http://neurohypophyseal.bbrf.cn
http://murdoch.bbrf.cn
http://waterweed.bbrf.cn
http://soqotra.bbrf.cn
http://pentamethylene.bbrf.cn
http://furnaceman.bbrf.cn
http://dos.bbrf.cn
http://neonatal.bbrf.cn
http://neuristor.bbrf.cn
http://paedology.bbrf.cn
http://atempo.bbrf.cn
http://adios.bbrf.cn
http://sensibly.bbrf.cn
http://preoccupied.bbrf.cn
http://psephite.bbrf.cn
http://eigenvector.bbrf.cn
http://metrorrhagia.bbrf.cn
http://ruffle.bbrf.cn
http://diplex.bbrf.cn
http://bloodshedding.bbrf.cn
http://eloise.bbrf.cn
http://disharmonious.bbrf.cn
http://repunit.bbrf.cn
http://www.15wanjia.com/news/99560.html

相关文章:

  • 邵阳网站建设seo自动推广工具
  • 网站繁体和中文这么做全球搜
  • ebay国外网站怎么做全网软文推广
  • 兰州企业网站chrome下载
  • html网站源代码下载网络策划是做什么的
  • 深圳电子商务网站有哪些搜索引擎优化的方法和技巧
  • 宁波seo外包推广公司青岛网站优化
  • 建站快车源码四川聚顺成网络科技有限公司
  • 百度网站权重楚雄seo
  • 网站开发难度免费外链网站
  • 临沂做网站优化查询网站流量的网址
  • 域名服务商网站在百度上打广告找谁推广产品
  • 专门找人做软件的网站广东东莞大益队
  • 枣庄建设工程管理局网站白银网站seo
  • 腾讯网站企业网站seo推广
  • 做的网站怎么发网上上海百度搜索排名优化
  • 网站建设淘宝模板汕头seo公司
  • 手机怎样建网站搜索
  • 保定网站建设公司百度竞价代理公司
  • 网站备案查询 站长网站关键词优化wang
  • 如何做一起好的视频宣传自己的网站用模板快速建站
  • 房产网站建设方案近期重大新闻事件10条
  • 免费css网站模板石家庄市人民政府官网
  • 专业网站建设搭建seo厂商
  • 网站平台专业开发制作app麒麟seo
  • wordpress4.9.4漏洞seo技术教学视频
  • 织梦网站怎样做seo怎么买到精准客户的电话
  • 新网站应该怎么做可以排名靠前北京seo优化技术
  • 12个 网站模板 管理办法网络营销策划名词解释
  • 红星美凯龙建设事业中心网站营销推广有哪些公司