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

无锡网站制作推广公司竞价排名采用什么计费方式

无锡网站制作推广公司,竞价排名采用什么计费方式,wordpress post url,做那个的网站谁有🧸安清h:个人主页 🎥个人专栏:【计算机网络】,【Mybatis篇】 🚦作者简介:一个有趣爱睡觉的intp,期待和更多人分享自己所学知识的真诚大学生。 文章目录 🎯初始Spring …

 

      🧸安清h:个人主页

   🎥个人专栏:【计算机网络】,【Mybatis篇】

🚦作者简介:一个有趣爱睡觉的intp,期待和更多人分享自己所学知识的真诚大学生。


 文章目录

🎯初始Spring 

🎯Spring的体系结构

🎯Spring的下载及目录结构

🎯Spring的入门程序

🚦pom.xml文件

🚦创建类Hello

🚦创建配置文件applicationContext.xml

🚦创建测试类

🎯控制反转与依赖注入

🚦控制反转概念

🚦依赖注入概念

🚦依赖注入类型

✨构造方法注入

🍔编写用户类

 🍔配置Bean信息

🍔编写测试类

✨setter方法注入

🍔编写用户类

 🍔配置Bean信息

🍔编写测试类

🚦依赖注入应用

🍔编写Dao层

🍔编写Service层

🍔编写applicationContext.xml配置文件

🍔编写测试类


🎯初始Spring 

Spring框架是一个开源的Java平台,用于简化企业级应用程序的开发。它提供了一系列的功能,使得开发者能够更容易地构建和维护应用程序。以下是Spring框架的一些主要优点:

  1. 依赖注入(DI):Spring通过依赖注入提供了一种松耦合的方式来组装应用程序的不同部分。
  2. 面向切面编程(AOP):Spring支持面向切面编程,允许开发者将横切关注点(如日志记录、事务管理等)与业务逻辑分离。
  3. 声明式事务管理:Spring提供了声明式事务管理,使得事务管理变得更加简单和透明。
  4.  集成多种数据访问技术:Spring整合了JDBC、Hibernate、JPA等数据访问技术,提供了一致的编程模式。
  5.  支持多种视图层技术:Spring支持多种视图层技术,如JSP、Thymeleaf、JSF等。
  6.  支持MVC:Spring提供了一个灵活的Web MVC框架,使得Web应用程序的开发更加简单。
  7. 轻量级:Spring框架本身是轻量级的,不会对应用程序的性能造成太大影响。
  8. 模块化:Spring框架是高度模块化的,开发者可以根据需要选择使用特定的模块。
  9. 支持多种配置方式:Spring支持XML、Java配置以及注解等多种配置方式。
  10. 支持响应式编程:Spring 5引入了对响应式编程的支持,使得开发非阻塞应用程序变得更加容易。

这些优点使得Spring成为Java企业级应用程序开发的首选框架之一。
 

🎯Spring的体系结构

Spring是模块化的,允许使用者只选择适用于自己的模块。下面对部分模块进行简单介绍:

  1. 核心容器

    • Spring Core:提供了依赖注入(DI)和面向切面编程(AOP)的支持。
    • Spring Beans:管理配置元数据,处理Bean的生命周期。
    • Spring Context:扩展了核心容器,提供了更高级的特性,如国际化支持、资源访问、事件传播等。
    • Spring Expression Language (SpEL):提供了强大的表达式语言,可以在运行时查询和操作对象图。

  2. 数据访问/集成

    • JDBC:提供JDBC抽象层,简化数据库操作。
    • ORM:整合了Hibernate、JPA等对象关系映射框架。
    • OXM:提供了对象XML映射的支持。
    • JMS:支持Java消息服务。
    • 事务管理:提供了声明式和编程式事务管理。
  3. Web

    • Spring MVC:实现了MVC模式,支持Web应用程序的开发。
    • Spring WebFlux:支持响应式编程的Web框架。
    • Spring Web Services:支持SOAP和RESTful Web服务。
  4. AOP
  1. 提供了面向切面编程的支持,允许开发者定义切面和通知。

🎯Spring的下载及目录结构

在使用Spring之前需要获取它的jar包,这些jar包可以在Spring官网下载。下载完成后会得到如下:

🎯Spring的入门程序

🚦pom.xml文件

在pom.xml文件中添加以下代码:

 <dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.8.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>5.2.8.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>5.2.8.RELEASE</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-expression</artifactId><version>5.2.8.RELEASE</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency></dependencies>

🚦创建类Hello

在包com.haust.pojo中编写类Hello,具体代码如下:

public class Hello {private String username;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public void show(){System.out.println(username+"欢迎来到Spring");}
}

🚦创建配置文件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/beanshttps://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="helloSpring" class="com.haust.pojo.Hello"><property name="username" value="清"></property></bean>
</beans>

🚦创建测试类

public class HelloTest {public static void main(String[]args){ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext.xml");Hello hello= (Hello) applicationContext.getBean("helloSpring");hello.show();}
}

🎯控制反转与依赖注入

🚦控制反转概念

控制反转(Inversion of Control,IoC)是一种设计原则,用来减少计算机编程中的耦合度。这个概念的核心思想是将对象之间的控制逻辑从对象本身转移到外部容器或框架中,从而实现解耦。

在传统的编程模式中,对象通常自己负责获取它们所需的依赖项,例如,通过直接创建对象或者从全局上下文中查找它们。这种方式会导致代码之间的高度耦合,使得代码难以测试、维护和重用。

控制反转通过以下两种主要方式实现:

  1. 依赖注入(Dependency Injection,DI): 这是控制反转最常见的形式。在依赖注入中,对象不需要自己查找或创建依赖项,而是被动地从外部“注入”这些依赖。依赖注入可以是显式的(通过构造函数、setter方法或接口)或隐式的(通过注解或约定)。

  2. 服务定位器模式(Service Locator pattern): 在服务定位器模式中,对象不直接创建或查找依赖项,而是通过一个中介(服务定位器)来访问它们。服务定位器负责查找和提供所需的依赖项。

控制反转的好处包括:

  • 降低耦合度:对象不再需要知道如何创建或查找它们的依赖项,因此减少了对象之间的依赖关系。
  • 提高模块化:由于依赖项是通过外部注入的,因此可以更容易地替换模块或组件。
  • 增强测试性:可以更容易地对对象进行单元测试,因为可以注入模拟(mock)对象或存根(stub)。
  • 提高代码的可读性和可维护性:代码更加清晰,因为对象不再包含复杂的逻辑来查找或创建依赖项。

🚦依赖注入概念

依赖注入(Dependency Injection,简称DI)是一种实现控制反转(Inversion of Control,IoC)的设计模式。它是一种编程技巧,用于减少代码间的耦合度,从而使得代码更容易测试、维护和重用。依赖注入的核心思想是将组件(对象)的依赖关系由外部传递进来,而不是由组件自己创建或查找依赖。

依赖注入的主要目的是:

  1. 降低组件之间的耦合度:组件不需要知道如何创建或获取它们的依赖项,这些依赖项将由外部提供。
  2. 提高组件的可测试性:由于依赖项是外部提供的,可以很容易地替换为模拟对象(mocks)或存根(stubs)进行单元测试。
  3. 增强代码的可读性和可维护性:组件的创建和依赖项的获取被分离,使得代码结构更清晰,更易于理解和维护。

🚦依赖注入类型

✨构造方法注入

在Spring框架中,构造方法注入是一种依赖注入的方式,它通过构造方法将所需的依赖项传递给Bean。这种方式通常被认为是更推荐的做法,因为它可以使Bean的状态更加明确,并且可以确保在创建Bean时所有的必需依赖项都已经准备好。下面通过一个示例来演示:

🍔编写用户类

public class User {private int id;private String username;private String password;public User(int id, String username, String password) {this.id = id;this.username = username;this.password = password;}@Overridepublic String toString() {return "User{" +"id=" + id +", username='" + username + '\'' +", password='" + password + '\'' +'}';}
}
 🍔配置Bean信息

在Spring的XML配置文件中,<constructor-arg> 标签用于构造方法注入。在这个例子中,<constructor-arg> 标签定义了传递给 User 类构造方法的参数。每个 <constructor-arg> 标签代表一个参数,并且可以通过 name 属性指定参数的名称,或者省略 name 属性,Spring将根据参数的位置来匹配。

在applicationContext-User.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/beanshttps://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="user1" class="com.haust.pojo.User"><constructor-arg name="id" value="1"/><constructor-arg name="username" value="lili"/><constructor-arg name="password" value="123456"/></bean>
</beans>
🍔编写测试类
public class UserTest {public static void main(String[]args){ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext-User.xml");User user=applicationContext.getBean("user1",User.class);System.out.println(user);}
}

✨setter方法注入

在Spring框架中,setter方法注入是一种常用的依赖注入方式,它利用类的setter方法来注入依赖项。这种方式的好处是可以在运行时改变Bean的属性值,从而提供了更大的灵活性。

以下是setter方法注入的一个简单示例:

🍔编写用户类

用户类中必须有setter方法

public class User2 {private int id;private String username;private String password;public void setId(int id) {this.id = id;}public void setUsername(String username) {this.username = username;}public void setPassword(String password) {this.password = password;}@Overridepublic String toString() {return "User2{" +"id=" + id +", username='" + username + '\'' +", password='" + password + '\'' +'}';}
}
 🍔配置Bean信息
    <bean id="user2" class="com.haust.pojo.User2"><property name="id" value="2"/><property name="username" value="popo"/><property name="password" value="123"/></bean>
🍔编写测试类
public class User2Test {public static void main(String[]args){ApplicationContext applicationContext=new ClassPathXmlApplicationContext("applicationContext-User.xml");User2 user=applicationContext.getBean("user2", User2.class);System.out.println(user);}}

🚦依赖注入应用

了解两种注入方式之后,下面通过一个示例,实现一个登录验证。

🍔编写Dao层

在dao包新建接口UserDao并添加login()方法实现登录功能:

public interface UserDao {public boolean login(String name,String password);
}

在impl包中新建UserDaoImpl类用来实现UserDao类中的login()方法:

public class UserDaoImpl implements UserDao {@Overridepublic boolean login(String name, String password) {if(name.equals("lili")&&password.equals("123")){return true;}return false;}
}
🍔编写Service层

在service包中新建接口UserService,UserService作为业务逻辑层接口:

public interface UserService {public boolean login(String name,String password);
}

在impl包中新建UserServiceImpl类用来实现UserService类中的login()方法:

public class UserServiceImpl implements UserService {private UserDao userDao;public void setUserDao(UserDao userDao) {this.userDao = userDao;}@Overridepublic boolean login(String name, String password) {return userDao.login(name, password);}
}
🍔编写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/beanshttps://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="userDao" class="com.haust.impl.UserDaoImpl"></bean><bean id="UserService" class="com.haust.impl.UserServiceImpl"><property name="userDao" ref="userDao"/></bean>
</beans>
🍔编写测试类
public class LoginTest {public static void main(String[] args) {ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");UserService userService = (UserService) applicationContext.getBean("userService");boolean flag = userService.login("lili", "123");if (flag) {System.out.println("登录成功");} else {System.out.println("登录失败");}}
}

 以上就是今天要讲的内容了,主要介绍了Spring入门的控制反转和依赖注入以及相关示例,如果您感兴趣的话,可以订阅我的相关专栏。非常感谢您的阅读,如果这篇文章对您有帮助,那将是我的荣幸。我们下期再见啦🧸!
 

http://www.dinnco.com/news/76130.html

相关文章:

  • 重庆快建网站西安网络推广seo0515
  • 百度推广做网站网店代运营哪个好
  • 成都网站开发培训机构佛山关键词排名效果
  • 哪里可以建设网站郑州做网站推广
  • 一个网站有多少页面头条收录提交入口
  • 广州做网站海珠新科注册公司
  • 武汉地铁建设西安自动seo
  • 网站定制系统数据处理软件seo是如何做优化的
  • 营销型网站建设深度网最新军事新闻 今日 最新消息
  • 国内十大网站建设公司排名软考培训机构哪家好一点
  • 360搜索联盟网站制作网址查询站长工具
  • pop布局网站网络营销主要有哪些特点
  • 大连市住房和城乡建设委员会网站sem账户托管公司
  • 广 做网站蓝光电影下载整站优化排名
  • 新时代政府网站建设交换链接
  • 做网站蓝色和什么颜色搭配好看公司网站设计的内容有哪些
  • iis配置网站无法浏览浙江专业网站seo
  • dw怎么做网站注册登入页面seo怎么优化武汉厂商
  • 如何用织梦做网站crm系统网站
  • 建工网校官网app网站推广优化网址
  • 婚纱网站模板net的网站建设
  • wordpress千位分隔符 阅卖次数seo赚钱培训课程
  • 开发平台指的是什么企业seo的措施有哪些
  • 广州网站建设怎么样网站推广技巧
  • 小公司网站建设app拉新推广平台渠道
  • 客服做的比较好的网站武汉seo系统
  • pc蛋蛋网站开发新手怎样做网络推广
  • 杭州哪里可以做网站推广谷歌seo
  • 义乌做网站如何提高网站排名seo
  • 如何建设网站的管理平台国外推广都是怎么推广