SSM集合

SSM集成

?

1.?Spring和各個框架的整合

?

Spring目前是JavaWeb開發中最終的框架,提供一站式服務,可以其他各個框架整合集成

?

Spring整合方案

?

1.1.?SSH

ssh是早期的一種整合方案

Struts2 Web層框架

Spring : 容器框架

Hibernate : 持久層框架

?

2.?SSM

主流的項目架構的三大框架(相對其他框架而言,最優秀)

?SpringMVC spring自己家的 Web層框架,spring的一個模塊

?Spring :容器框架

?MyBatis :持久層框架

?

?

3.?SpringMyBatis整合

3.1.?集成思路

實際開發,使用Maven項目,直接引入項項目在Maven倉庫中的坐標即可

?

學習階段: 手動導入jar包,從零開始集成(鞏固基礎知識)

?

3.2.?創建java項目

?

?

?

3.3.?準備集成相關jar

3.3.1.?Spring依賴包

?

?

3.3.2.?SpringMVC依賴包

?

?

?

3.3.3.?Mybatis依賴包

?

?

3.3.4.?MyBatisSpring框架集成的橋梁包

Spring自己并沒有集成MyBatis框架,需要MyBatis自己來集成,所以需要自己提供Spring框架集成的橋梁包

?

如果我們使用的mybatis3.4.4 不能直接使用mybatis內置的 橋梁包版本,版本比較低,無法正常運行,需要單獨下載一個比價高的版本

?

?

3.3.5.?數據庫驅動包和連接池

?

?

?

?

?

3.3.6.?Jstl標簽庫依賴包

?

?

?

3.3.7.?Mybatis支持的日志包log4j

?

?

3.4.?項目集成需要各種配置文件

?

?

?

3.5.?Mapper

package?cn.zj.ssm.mapper;

?

import?java.util.List;

?

import?cn.zj.ssm.pojo.User;

?

public?interface?UserMapper {

?

int?insert(User user);

?

User selectByPrimaryKey(Integer id);

?

?

List<User> selectList();

?

int?delteByPrimaryKey(Integer id);

}

?

?

3.5.1.?Mapperxml文件

<?xml?version="1.0"?encoding="UTF-8"??>

<!DOCTYPE?mapper

??PUBLIC?"-//mybatis.org//DTD Mapper 3.0//EN"

??"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

?

<mapper?namespace="cn.zj.ssm.mapper.UserMapper">

?

<insert?id="insert"?parameterType="cn.zj.ssm.pojo.User">

insert into user (name,password,age)values(#{name},#{password},#{age})

</insert>

?

<select?id="selectByPrimaryKey"?parameterType="Integer"?resultType="cn.zj.ssm.pojo.User">

select * from user where id = #{id}

</select>

?

<select?id="selectList"??resultType="cn.zj.ssm.pojo.User">

select * from user

</select>

??

?? <delete?id="delteByPrimaryKey"?parameterType="int">

?? delete from user where id = #{id}

?? </delete>

??

</mapper>

?

3.6.?完成項目層與層之間spring對象的創建和依賴關系的維護

3.6.1.?Service

package?cn.zj.ssm.service.impl;

?

import?java.util.List;

?

import?org.springframework.beans.factory.annotation.Autowired;

import?org.springframework.stereotype.Service;

?

import?cn.zj.ssm.mapper.UserMapper;

import?cn.zj.ssm.pojo.User;

import?cn.zj.ssm.service.UserService;

?

@Service

public?class?UserServiceImpl implements?UserService {

/*

?* 問題: UserMapper 代理對象如何創建?

?* 答 :使用 SqlSession 操作對象創建 !

?*

?* 問題 : SqlSession 對象如何創建?

?* ?

?* 答 : SqlSessionFactory 工廠對象創建?

?*

?* 問題: SqlSessionFactory 對象如何創建

?*

?* 1,和Spring框架集成之前

?* ?MyBatis框架自己讀取配置文件中的相關配置去創建

?* 2, 和Spring框架集成之后

?* ?交個Spring容器來創建

?* 問題: 如何在Spring框架中配置,創建出來SqlSessionFactory對象?

?* ?mybatis和spring集成的類查閱 橋梁包

?* ?org.mybatis.spring.SqlSessionFactoryBean 創建 SqlSessionFactory

?*

?*/

@Autowired

private?UserMapper mapper;

?

@Override

public?int?insert(User user) {

return?mapper.insert(user);

}

?

@Override

public?User selectByPrimaryKey(Integer id) {

System.out.println(mapper);

return?mapper.selectByPrimaryKey(id);

}

?

@Override

public?List<User> selectList() {

return?mapper.selectList();

}

?

@Override

public?int?delteByPrimaryKey(Integer id) {

return?mapper.delteByPrimaryKey(id);

}

?

?

?

}

?

3.6.2.?測試代碼

package?cn.zj.ssm.test;

?

import?java.util.List;

?

import?org.junit.Test;

import?org.junit.runner.RunWith;

import?org.springframework.beans.factory.annotation.Autowired;

import?org.springframework.test.context.ContextConfiguration;

import?org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

?

import?cn.zj.ssm.pojo.User;

import?cn.zj.ssm.service.UserService;

?

@RunWith(SpringJUnit4ClassRunner.class)

@ContextConfiguration("classpath:spring.xml")

public?class?UserServiceTest {

?

@Autowired

private?UserService service;

?

@Test

public?void?testInsert() {

User user?= new?User(null, "喬峰", "qiaofeng", 30);

int?row?= service.insert(user);

System.out.println(row);

?

}

?

@Test

public?void?testSelectByPrimaryKey() {

User user?= service.selectByPrimaryKey(8);

System.out.println(user);

}

?

@Test

public?void?testSelectList() throws?Exception {

List<User> users?= service.selectList();

?

for?(User user?: users) {

System.out.println(user);

}

}

?

}

?

?

3.6.3.?applicationContext配置文件的配置

<?xml?version="1.0"?encoding="UTF-8"?>

<beans?xmlns="http://www.springframework.org/schema/beans"

xmlns:p="http://www.springframework.org/schema/p"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="

????http://www.springframework.org/schema/beans

????????http://www.springframework.org/schema/beans/spring-beans.xsd

????????http://www.springframework.org/schema/context

????????http://www.springframework.org/schema/context/spring-context.xsd

????????http://www.springframework.org/schema/aop

????????http://www.springframework.org/schema/aop/spring-aop.xsd

????????http://www.springframework.org/schema/tx

????????http://www.springframework.org/schema/tx/spring-tx.xsd

????????">

?

?

<!-- 設置注解配置包掃描位置 -->

<context:component-scan base-package="cn.zj.mybatis"/>

?

</beans>

?

3.7.?MyBatis 框架SqlSessionFactory對象的創建

?

?* 問題: UserMapper 代理對象如何創建?

?* 答 :使用 SqlSession 操作對象創建 !

?*

?* 問題 : SqlSession 對象如何創建?

?* ?

?* : SqlSessionFactory 工廠對象創建?

?*

?* 問題: SqlSessionFactory 對象如何創建

?*

?* 1,和Spring框架集成之前

?* ?MyBatis框架自己讀取配置文件中的相關配置去創建

?* 2, 和Spring框架集成之后

?* ?交個Spring容器來創建

?* 問題: 如何在Spring框架中配置,創建出來SqlSessionFactory對象?

?* ?mybatisspring集成的類查閱 橋梁包

?* ?org.mybatis.spring.SqlSessionFactoryBean 創建 SqlSessionFactory

?*

?*/

創建MyBatis框架工廠對象的 類在mybatis-spring1.2.1.jar 橋梁包中的

org.mybatis.spring.SqlSessionFactoryBean? 如下圖

?

?

?

3.7.1.?配置文件

<?xml?version="1.0"?encoding="UTF-8"?>

<beans?xmlns="http://www.springframework.org/schema/beans"

xmlns:p="http://www.springframework.org/schema/p"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="

????http://www.springframework.org/schema/beans

????????http://www.springframework.org/schema/beans/spring-beans.xsd

????????http://www.springframework.org/schema/context

????????http://www.springframework.org/schema/context/spring-context.xsd

????????http://www.springframework.org/schema/aop

????????http://www.springframework.org/schema/aop/spring-aop.xsd

????????http://www.springframework.org/schema/tx

????????http://www.springframework.org/schema/tx/spring-tx.xsd

????????">

?

?

<!-- 配置讀取 db.properties 數據庫配置文件 -->

<context:property-placeholder?location="classpath:db.properties"/>

?

<!-- 配置數據源連接池 -->

<bean?id="dataSource"?class="com.alibaba.druid.pool.DruidDataSource"?init-method="init"?destroy-method="close">

<property?name="driverClassName"?value="${jdbc.driverClassName}"/>

<property?name="url"?value="${jdbc.url}"/>

<property?name="username"?value="${jdbc.username}"/>

<property?name="password"?value="${jdbc.password}"/>

<property?name="maxActive"?value="${jdbc.maxActive}"/>

</bean>

?

?

<!--

配置MyBatis框架的 SqlSessionFactoryBean 類,創建

?

?SqlSessionFactory 工廠對象

?-->

<bean?id="sqlSessionFactory"?class="org.mybatis.spring.SqlSessionFactoryBean">

<!-- 1.注入數據源 -->

<property?name="dataSource"?ref="dataSource"/>

?

?

<!-- 2.配置映射文件 -->

<property?name="mapperLocations">

<array>

<!-- <value>classpath:cn/zj/mybatis/mapper/UserMapper.xml</value> -->

<!-- 可以使用通配符 * 讀取 目錄下面所有的配置文件 -->

<value>classpath:cn/zj/mybatis/mapper/*Mapper.xml</value>

</array>

</property>

?

<!-- 3. 配置別名使用包掃描 -->

<property?name="typeAliasesPackage"?value="cn.zj.mybatis.pojo"/>

?

<!-- 4.讀取mybat-config.xml配置文件,此配置文件可能還會配一些mybatis框架的

其他個性化配置

實際項目開發可能不用配置

?-->

?<property?name="configLocation"?value="classpath:mybatis-config.xml"/>

</bean>

</beans>

3.8.?創建MyBatisMapper接口的代理對象

使用橋梁包 org.mybatis.spring.mapper.MapperFactoryBean<T> 創建 UserMapper代理對象

?

?

?

此種方式每一個Mapper接口需要單獨配置,如果Mapper過多,創建Mapper可能造成配置代碼過多

?? ?<!-- 創建UserMapper代理對象-創建單個Mapper對象

???

?使用橋梁包 org.mybatis.spring.mapper.MapperFactoryBean<T> 創建 UserMapper代理對象

??-->

??

??<bean?id="userMapper"?class="org.mybatis.spring.mapper.MapperFactoryBean">

??

?? <!-- 注入SqlSessionFacotry對象 -->

?? <property?name="sqlSessionFactory"?ref="sqlSessionFactory"/>

??

?? <!-- 注入UserMapper接口類型:底層創建UserMapper的代理對象 -->

?? <property?name="mapperInterface"?value="cn.zj.mybatis.mapper.UserMapper"/>

??

??</bean>

?

?

3.9.?使用包掃描創建MyBatisMapper接口的代理對象

?

?

?

?

<!-- 批量創建Mapper代理對象 ,使用包掃描創建Mapper代理對象

??使用橋梁包

??org.mybatis.spring.mapper.MapperScannerConfigurer

??-->

??

??<bean?class="org.mybatis.spring.mapper.MapperScannerConfigurer">

?? <!-- 配置需要創建Mapper接口代理對象對應的包 -->

?? <property?name="basePackage"?value="cn.zj.mybatis.mapper"/>

??

?? <!-- 配置SqlSessionFactoryBean 的名稱,不是引用 -->

?? <property?name="sqlSessionFactoryBeanName"?value="sqlSessionFactory"/>

??</bean>

?

3.10.?MyBatis的事務管理器的配置

一般開發,事務的管理都會使用aop切入到業務層

?

??<!-- 配置事務管理器 -->

??<bean?id="transactionManager"?class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

?? <!-- 注入數據源 -->

?? <property?name="dataSource"?ref="dataSource"/>

??</bean>

??

??<!-- spring事務配置 -->

??<tx:advice?id="txAdvice"?transaction-manager="transactionManager">

??

?? <!-- 事務屬性配置 -->

?? <tx:attributes>

?? <!-- DQL :查詢操作,配置只讀事務 -->

?? <tx:method?name="get*"?read-only="true"?isolation="REPEATABLE_READ"??propagation="REQUIRED"/>

?? <tx:method?name="select*"?read-only="true"?isolation="REPEATABLE_READ"??propagation="REQUIRED"/>

?? <tx:method?name="find*"?read-only="true"?isolation="REPEATABLE_READ"??propagation="REQUIRED"/>

?? <tx:method?name="query*"?read-only="true"?isolation="REPEATABLE_READ"??propagation="REQUIRED"/>

??

?? <!-- 其他 SQL :非只讀事務 -->

?? <tx:method?name="*"?read-only="false"?isolation="REPEATABLE_READ"??propagation="REQUIRED"/>

??

?? </tx:attributes>

??

??</tx:advice>

??

??<!-- 配置AOP 切入事務 -->

??

??<aop:config>

?? <!-- 切入點 -->

?? <aop:pointcut?expression="execution(* cn.zj.mybatis.service..*.*(..))"?id="pt"/>

??

?? <!-- 切面 -->

?? <aop:advisor?advice-ref="txAdvice"?pointcut-ref="pt"/>

??</aop:config>

?

?

4.?SpringMVC的集成

4.1.?在在web.xml配置SpringMVC的前端控制器

<?xml?version="1.0"?encoding="UTF-8"?>

<web-app?xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"?xmlns="http://java.sun.com/xml/ns/javaee"?xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"?version="3.0">

?

<!-- 配置字符編碼過濾器 -->

<filter>

<filter-name>CharacterEncodingFilter</filter-name>

<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

</filter>

<filter-mapping>

<filter-name>CharacterEncodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

?

?

<!-- 配置前端控制器 -->

<servlet>

<servlet-name>MVC</servlet-name>

<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

?

<!-- 讀取配置文件

問題:有多個spring相關配置文件如何讀取

如 :spring.xml 和springmvc.xml

?

解決方案:

方案一:直接使用 統配 * 可以讀取多個有相同前綴的文件

<param-value>classpath:spring*.xml</param-value>

方案二:先讀取一個配置文件 如果 spring.xml

再在spring.xml文件中使用<import>標簽導入 springmvc.xml文件

<import resource="classpath:springmvc.xml"/>

?-->

?

<param-value>classpath:spring.xml</param-value>

</init-param>

?

<load-on-startup>1</load-on-startup>

?

</servlet>

<servlet-mapping>

<servlet-name>MVC</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

?

</web-app>

4.1.1.?springmvc.xml配置文件

<?xml?version="1.0"?encoding="UTF-8"?>

<beans?xmlns="http://www.springframework.org/schema/beans"

xmlns:p="http://www.springframework.org/schema/p"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="

http://www.springframework.org/schema/beans

????????http://www.springframework.org/schema/beans/spring-beans.xsd

????????http://www.springframework.org/schema/mvc

????????http://www.springframework.org/schema/mvc/spring-mvc.xsd

????????">

<!-- 配置springmvc的注解驅動 -->

<mvc:annotation-driven/>

?

</beans>

?

?

4.2.?編寫控制器 UserController

package?cn.zj.ssm.controller;

?

import?java.util.List;

?

import?org.springframework.beans.factory.annotation.Autowired;

import?org.springframework.stereotype.Controller;

import?org.springframework.ui.Model;

import?org.springframework.web.bind.annotation.RequestMapping;

?

import?cn.zj.ssm.pojo.User;

import?cn.zj.ssm.service.UserService;

?

@Controller

@RequestMapping("/user")

public?class?UserController {

?

@Autowired

private?UserService service;

?

@RequestMapping("/list")

public?String list(Model m) {

?

//調用service查詢所有用戶方法

List<User> users?= service.selectList();

?

//共享數據

m.addAttribute("users", users);

?

return?"/WEB-INF/view/user_list.jsp";

}

?

?

@RequestMapping("/delete")

public?String delete(Integer id) {

System.out.println(id);

?

//調用service層的刪除方法

service.delteByPrimaryKey(id);

?

return?"redirect:/user/list.do";

}

?

}

?

?

4.3.?user_list.jsp 頁面

jsp頁面 使用jstl標簽庫需要先在頁面引入jstl 標簽庫

<%@?page?language="java"?contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!-- 引入jstl標簽庫 ?-->

<%@?taglib?uri="http://java.sun.com/jsp/jstl/core"?prefix="c"%>

<!DOCTYPE?html>

<html>

<head>

<meta?charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

<h3>用戶列表</h3>

?

<table?border="1"?style="width: 500px;" cellspacing="0">

<tr>

<th>id</th>

<th>名稱</th>

<th>密碼</th>

<th>年齡</th>

<th>操作</th>

</tr>

?

?

<c:forEach?items="${users}"?var="user">

<tr>

<td>${user.id}</td>

<td>${user.name}</td>

<td>${user.password}</td>

<td>${user.age}</td>

<td>

<a?href="javascript:void(0);"?οnclick="deleteByPrimaryKey(${user.id})">刪除</a>???

<a?href="">修改</a>

</td>

</tr>

</c:forEach>

</table>

?

<script?type="text/javascript">

?

function?deleteByPrimaryKey(userId){

?

if(confirm("親,您確定刪除此條數據么?")){

window.location.href= "${pageContext.request.contextPath}/user/delete.do?id="+userId;

}

}

?

</script>

?

</body>

</html>

轉載于:https://www.cnblogs.com/FSY15767366954/p/11172558.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/448377.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/448377.shtml
英文地址,請注明出處:http://en.pswp.cn/news/448377.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

淺談 CSRF 攻擊方式

前些天發現了一個巨牛的人工智能學習網站&#xff0c;通俗易懂&#xff0c;風趣幽默&#xff0c;忍不住分享一下給大家。點擊跳轉到教程。 一.CSRF是什么&#xff1f; CSRF&#xff08;Cross-site request forgery&#xff09;&#xff0c;中文名稱&#xff1a;跨站請求偽造&a…

C++之運算符重載(上)

1、概念 所謂重載&#xff0c;就是重新賦予新的含義。函數重載就是對一個已有的函數賦予新的含義&#xff0c;使之實現新功能&#xff0c;因此&#xff0c;一個函數名就可以用來代表不同功能的函數&#xff0c;也就是”一名多用”。 運算符也可以重載。實際上&#xff0c;我們…

手剎

定義 考手剎的專業稱呼是輔助制動器&#xff0c;與制動器的原理不同&#xff0c;其是采用鋼絲拉線連接到后制動蹄上&#xff0c;以對車子進行制動。作用 用于平地斜坡停車時制動&#xff0c;防止車子在無人狀態下自動滑跑&#xff0c;逼免發生交通事故。工作原理 其原…

關于[super dealloc]

銷毀一個對象時&#xff0c;需要重寫系統的dealloc方法來釋放當前類所擁有的對象&#xff0c;在dealloc方法中需要先釋放當前類中所有的對象&#xff0c;然后再調用[super dealloc]釋放父類中所擁有的對象。如先調用[super dealloc]將釋放掉父類中所擁有的對象&#xff0c;當前…

C++之運算符重載(下)

4.提高 1.運算符重載機制 編譯器實現運算符重載實際上就是通過函數重載實現的&#xff0c;可分為全局函數方式&#xff0c;也可分為成員函數方式進行重載&#xff0c;并沒有改變原操作符的屬性和語義。只是針對某個特定類定義一種新的數據類型操作。 2.重載賦值運算符 賦值…

Cookie / Session 的機制與安全

前些天發現了一個巨牛的人工智能學習網站&#xff0c;通俗易懂&#xff0c;風趣幽默&#xff0c;忍不住分享一下給大家。點擊跳轉到教程。 Cookie和Session是為了在無狀態的HTTP協議之上維護會話狀態&#xff0c;使得服務器可以知道當前是和哪個客戶在打交道。本文來詳細討論C…

手動擋

定義 手動擋&#xff0c;即用手撥動變速桿才能改變變速器內的齒輪嚙合置&#xff0c;改變傳動比&#xff0c;從而達到變速的目的。作用 一方面提供了手動的樂趣 另外一方面就是通過手動自主控制轉速&#xff0c;還可以遲延或提前換檔。駕駛技巧 市區內應直視前方五…

Servlet快速入門及運行流程

一、Servlet快速入門 1.創建一個web工程 2.在JavaResource中src下創建一個包名稱為com.myxq.servlet 3.在創建的servlet包當中創建一個class文件起名為FirstServlet 4.進入該class實現一個Servlet接口&#xff0c;實現它未實現的方法 重點看service方法在該方法當中寫入一句話進…

C++之多繼承

1.基礎知識 1.1 類之間的關系 has-A&#xff0c;uses-A 和 is-A has-A 包含關系&#xff0c;用以描述一個類由多個“部件類”構成。實現has-A關系用類成員表示&#xff0c;即一個類中的數據成員是另一種已經定義的類。 常和構造函數初始化列表一起使用 uses-A 一個類部分地…

自動擋

定義 所謂自動擋&#xff0c;就是不用駕駛者去手動換檔&#xff0c;車輛會根據行駛的速度和交通情況自動選擇合適的檔位行駛。作用 能根據路面狀況自動變速&#xff0c;使駕駛者可以全神貫地注視路面交通而不會被換檔搞得手忙腳亂。工作原理 自動變速器&#xff0c…

聊一聊 cookie

我們看到的 cookie 前些天發現了一個巨牛的人工智能學習網站&#xff0c;通俗易懂&#xff0c;風趣幽默&#xff0c;忍不住分享一下給大家。點擊跳轉到教程。 我自己創建了一個網站&#xff0c;網址為http://ppsc.sankuai.com。在這個網頁中我設置了幾個cookie&#xff1a;JS…

跨域資源共享 CORS 詳解

前些天發現了一個巨牛的人工智能學習網站&#xff0c;通俗易懂&#xff0c;風趣幽默&#xff0c;忍不住分享一下給大家。點擊跳轉到教程。 CORS是一個W3C標準&#xff0c;全稱是"跨域資源共享"&#xff08;Cross-origin resource sharing&#xff09;。 它允許瀏覽…

油門

定義 油門是內燃機上控制燃料供量的裝置。作用 是汽車發動機與摩托車油箱之間的閥門&#xff0c;控制汽油的量。操作注意 1.空車起步勿用大油門&#xff0c;以小油門為宜&#xff0c;負荷起步則以中油門為宜。 2.啟動時將油門放在合適位&#xff0c;使機件不易磨損。…

C++之泛型編程(模板)

1.模板綜述 背景 有時候許多函數或子程序的邏輯結構是一樣的&#xff0c;只是要處理的數據類型不一樣有時候多個類具有相同邏輯的成員函數和成員變量&#xff0c;只是成員變量的數據類型以及成員函數的參數類型不一樣模板就是解決數據類型不一致造成代碼冗余的一種機制&#xf…

Base64轉PDF、PDF轉IMG(使用pdfbox插件)

--添加依賴 <!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox --><dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox</artifactId> <version>2.0.12</version></dependency&…

const的用法,特別是用在函數后面

原文出處&#xff1a;http://blog.csdn.net/zcf1002797280/article/details/7816977

圖解 Linux 安裝 JDK1.8 、配置環境變量

前些天發現了一個巨牛的人工智能學習網站&#xff0c;通俗易懂&#xff0c;風趣幽默&#xff0c;忍不住分享一下給大家。點擊跳轉到教程。 1. 到官網下載 JDK 1.8 https://www.oracle.com/technetwork/java/javase/downloads/index.html 2. 用 rz 命令把 jdk-8u191-linux-x6…

剎車

定義 剎車就是可以減慢車速的機械制動裝置&#xff0c;又名減速器。簡單來說&#xff0c;汽車剎車踏板在方向盤下面&#xff0c;踩住剎車踏板&#xff0c;則使剎車杠桿聯動受壓并傳至到剎車鼓上的剎車片卡住剎車輪盤&#xff0c;使汽車減速或停止運行。作用 目的是減速&a…

【原創】Performanced C++ 經驗規則 第五條:再談重載、覆蓋和隱藏

第五條&#xff1a;再談重載、覆蓋和隱藏 在C中&#xff0c;無論在類作用域內還是外&#xff0c;兩個&#xff08;或多個&#xff09;同名的函數&#xff0c;可能且僅可能是以下三種關系&#xff1a;重載&#xff08;Overload&#xff09;、覆蓋&#xff08;Override&#xff0…

C++之純虛函數和抽象類

純虛函數和抽象類 1.基本概念 2.案例 #include <iostream> using namespace std;////面向抽象類編程(面向一套預先定義好的接口編程)//解耦合 ....模塊的劃分class Figure //抽象類 { public://閱讀一個統一的界面(接口),讓子類使用,讓子類必須去實現virtual void get…