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

酷炫个人特别网站八上数学优化设计答案

酷炫个人特别网站,八上数学优化设计答案,个人做网站猛赚钱,搬瓦工 做网站目录 一、Spring框架的介绍 1.1 Spring框架的概述 1.2 Spring框架的优点 二、Spring的核心 IOC技术 2.1 什么是IOC 2.2 IOC的程序入门 2.3 IOC技术总结 2.4 Spring框架的Bean管理的配置文件方式 一、Spring框架的介绍 1.1 Spring框架的概述 Spring是一个开放源代码的…

目录

一、Spring框架的介绍

1.1 Spring框架的概述

1.2 Spring框架的优点

 二、Spring的核心 IOC技术

2.1 什么是IOC

2.2 IOC的程序入门

2.3 IOC技术总结

2.4 Spring框架的Bean管理的配置文件方式 


一、Spring框架的介绍

1.1 Spring框架的概述

Spring是一个开放源代码的设计层面框架,它解决的是业务逻辑层和其他各层的松耦合问题,因此它将面向接口的编程思想贯穿整个系统应用。Spring的核心是控制反转(IoC控制反转)和面向切面(AOP)。简单来说,Spring是一个分层的JavaSE/EEfull-stack(一站式) 轻量级开源框架。

1.2 Spring框架的优点

1.方便解耦,简化开发,Spring就是一个大工厂,可以将所有对象创建和依赖关系维护,交给Spring管理。(IOC的作用)

2.AOP编程的支持,Spring提供面向切面编程,可以方便的实现对程序进行权限拦截、运行监控等功能。可扩展性

3.声明式事务的支持,只需要通过配置就可以完成对事务的管理,而无需手动编程。

4.方便程序的测试,Spring对Junit4支持,可以通过注解方便的测试Spring程序。

5.方便集成各种优秀框架,Spring不排斥各种优秀的开源框架,其内部提供了对各种优秀框架(如:Struts2、Hibernate、MyBatis、Quartz等)的直接支持。

6.降低JavaEE API的使用难度,Spring 对JavaEE开发中非常难用的一些API(JDBC、JavaMail、远程调用等),都提供了封装,使这些API应用难度大大降低。

 二、Spring的核心 IOC技术

2.1 什么是IOC

IOC -- Inverse of Control,控制反转,将对象的创建权力反转给Spring框架!!

控制反转(Inversion of Control,缩写为IoC),是面向对象编程中的一种设计原则,可以用来减低计算机代码之间的耦合度。

解决问题:使用IOC可以解决的程序耦合性高的问题!!Spring的工厂读取配置文件。

2.2 IOC的程序入门

项目中的目录结构:

controller(表现层):

controller层的功能为请求和响应控制
controller层负责前后端交互,接受前端请求,调用service层,接收service层返回的数据,最后返回具体的页面和数据到客户端

dao(持久层):也被称为mapper层

dao层的作用为访问数据库,向数据库发送sql语句,完成数据的增删改查任务

pojo(数据库实体类):也被称为entity层,model层

一般数据库一张表对应一个实体类,类属性同表字段一一对应

service(业务层):
service层的作用为完成功能设计
service层调用dao层接口,接收dao层返回的数据,完成项目的基本功能设计

utils(工具类):

存放了一些公共部分的工具类,主要是用于减少项目开发中的重复代码

步骤:

① 创建普通maven Java工程不需要界面所以不用创建web项目,需要导入spring依赖,所以创建普通maven Java项目即可,导入坐标依赖

    <dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.0.2.RELEASE</version></dependency><dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.2</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.12</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version><scope>test</scope></dependency></dependencies>

② 编写接口和实现类,编写具体的实现方法

package com.qcby.service;/*** 业务层接口* 用户模块接口* 目的:演示springIOC入门*/
public interface UserService {//接口中的抽象方法public void hello();
}
package com.qcby.service.impl;import com.qcby.service.UserService;/*** 用户模块实现类实现用户模块接口* 实现其抽象方法* 耦合度低*/
public class UserServiceImpl implements UserService {//实现入门@Overridepublic void hello() {System.out.println("Hello IOC!!");}}

③ 编写Spring核心的配置文件,在 src/main/resources 目录下创建 applicationContext.xml 的配置文件,名称是可以任意的,但是一般都会使用默认名称

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><!--IOC管理bean--><!--bean的意义是将该类的创建对象权力转给spring框架--><bean id="userService" class="com.qcby.service.impl.UserServiceImpl" /></beans>

④ 把log4j.properties的配置文件拷贝到 src/main/resources 目录下,做为 log4j 的日志配置文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"><log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"><appender name="STDOUT" class="org.apache.log4j.ConsoleAppender"><param name="Encoding" value="UTF-8"/><layout class="org.apache.log4j.PatternLayout"><param name="ConversionPattern" value="%-5p %d{MM-dd HH:mm:ss,SSS} %m  (%F:%L) \n"/></layout></appender><logger name="java.sql"><level value="debug"/></logger><logger name="org.apache.ibatis"><level value="info"/></logger><root><level value="debug"/><appender-ref ref="STDOUT"/></root>
</log4j:configuration>

⑤ 编写测试方法

package com.qcby.demo;import com.qcby.service.UserService;
import com.qcby.service.impl.UserServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;/*** 测试类* 测试UserService交给spring管理* IOC入门*/
public class UserServiceTest {@Testpublic void run1(){UserService userService = new UserServiceImpl();UserService userService1 = new UserServiceImpl();userService.hello();userService1.hello();System.out.println(userService);System.out.println(userService1);}@Testpublic void run2(){// 使用Spring的工厂ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");// 通过工厂获得类:UserService userService = (UserService) applicationContext.getBean("userService");UserService userService1 = (UserService) applicationContext.getBean("userService");userService.hello();userService1.hello();System.out.println(userService);System.out.println(userService1);}
}

运行 run1() 方法,可以看到,使用new方法直接创建对象是创建了两个不同的对象,这种做法在某些情况下可能会导致资源浪费,所以我们选择 run2() 的方法进行创建对象

运行 run2() 方法,可以看到,虽然创建了两个对象,但他们两个是单例,是相同的,只创建了一个对象,可以对之前创建的对象进行重复使用(使用这种方法也可以选择多例进行创建,默认是单例,可以在bean中进行属性设置也可以达成 run1() 中效果)

2.3 IOC技术总结

ApplicationContext接口,工厂的接口,使用该接口可以获取到具体的Bean对象。

该接口下有两个具体的实现类:

ClassPathXmlApplicationContext,加载类路径下的Spring配置文件,使用方法如下:

ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");

FileSystemXmlApplicationContext,加载本地磁盘下的Spring配置文件,使用方法如下:

ApplicationContext applicationContext = new FileSystemXmlApplicationContext("C:\\Users\\ZSW\\Desktop\\idea\\SpringIOC\\src\\main\\resources\\applicationContext.xml");

推荐使用ClassPathXmlApplicationContext,因为第二种写的是本地磁盘下的绝对路径,在真正开发项目时不易修改使用

2.4 Spring框架的Bean管理的配置文件方式 

id属性,自己对Bean起的名字,在约束中采用ID的约束,唯一,取值要求:必须以字母开始,可以使用字母、数字、连字符、下划线、句话、冒号 id:不能出现特殊字符

class属性,Bean对象的全路径

scope属性,scope属性代表Bean的作用范围

        singleton单例(默认值),最常用的方式

        prototype多例

Bean对象的创建和销毁的两个属性配置:

说明:Spring初始化bean或销毁bean时,有时需要作一些处理工作,因此spring可以在创建和拆卸bean的时候调用bean的两个生命周期方法

init-method,当bean被载入到容器的时候调用init-method属性指定的方法

destroy-method,当bean从容器中删除的时候调用destroy-method属性指定的方法


文章转载自:
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://.
http://www.tj-hxxt.cn/news/36520.html

相关文章:

  • 深圳设计网站培训关键词排名推广
  • 做宣传单用什么网站找图片西安seo
  • web网站开发怎么盈利dz论坛seo
  • 常州做网站公司排名自己怎么免费做网站
  • 2003总是说网站建设中亚马逊seo是什么意思
  • 北京和君网站建设市场调研分析报告
  • wordpress多站点用户互通18款禁用看奶app入口
  • 洛阳做网站哪家便宜外贸seo
  • 南京个人网站建设seo关键词排名优化方案
  • 有没有免费做英语题的网站百度权重10的网站
  • 网站建设与管理好找工作吗东莞优化疫情防控措施
  • 网站开发所需要的语言微营销推广软件
  • 网站备案名称能重复吗新媒体运营培训班
  • 网站后台报表统计系统百度智能云官网
  • 传奇新开服网站百度seo2022
  • wordpress插件 标签seo关键词优化是什么意思
  • 外贸哪个职位最吃香seo优化一般包括哪些内容()
  • 如何进行网站推广品牌公关
  • 政务网站开发视频号最新动作
  • 唐山建设网站建站网推什么意思
  • 做淘宝导航网站网络营销职业规划300字
  • chinacd.wordpress.net广州网站优化多少钱
  • 做企业网站注意什么深圳百度推广开户
  • 做网站协调淘宝指数
  • 怎么把网站放到服务器上百度认证中心
  • 网站不备案什么意思百度热搜榜排名今日
  • 口碑最好的装饰公司临沂seo推广
  • 海阔天空网站建设百度网盘官网登录入口
  • 培训网站开发企业产品营销策划推广
  • ppt模板资源网站十大网站排行榜