Spring 的持久化實例(JDBC, JdbcTemplate、HibernateDaoSupport、JdbcDaoSupport、SqlSessionDaoSupport等)...

2019獨角獸企業重金招聘Python工程師標準>>> hot3.png

一、表(這里用mysql,數據庫名為yiibai)

CREATE TABLE `customer` (`CUST_ID` int(10) UNSIGNED NOT NULL,`NAME` varchar(100) NOT NULL,`AGE` int(10) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ALTER TABLE `customer`ADD PRIMARY KEY (`CUST_ID`);

二、不用JdbcTemplate的情況

表的實體類Customer

package com.yiibai.springjdbc.bean;public class Customer {int custId;String name;int age;public Customer(int custId, String name, int age) {super();this.custId = custId;this.name = name;this.age = age;}public int getCustId() {return custId;}public void setCustId(int custId) {this.custId = custId;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Customer [custId=" + custId + ", name=" + name + ", age=" + age + "]";}
}

DAO接口

package com.yiibai.springjdbc.dao;import java.util.List;
import com.yiibai.springjdbc.bean.Customer;public interface CustomerDAO {public void insert(Customer customer);public Customer findByCustomerId(int custId);public List<Customer> queryCustomer() throws Exception ;
}

DAO實現(不用JdbcTemplate)

package com.yiibai.springjdbc.daoimpl;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;import javax.sql.DataSource;import com.yiibai.springjdbc.bean.Customer;
import com.yiibai.springjdbc.dao.CustomerDAO;public class CustomerImplDAO implements CustomerDAO {private DataSource dataSource;@Overridepublic void insert(Customer customer) {// TODO 自動生成的方法存根String sql = "INSERT INTO customer " + "(CUST_ID, NAME, AGE) VALUES (?, ?, ?)";Connection conn = null;try {conn = dataSource.getConnection();PreparedStatement ps = conn.prepareStatement(sql);ps.setInt(1, customer.getCustId());ps.setString(2, customer.getName());ps.setInt(3, customer.getAge());ps.executeUpdate();ps.close();} catch (SQLException e) {throw new RuntimeException(e);} finally {if (conn != null) {try {conn.close();} catch (SQLException e) {}}}}@Overridepublic Customer findByCustomerId(int custId) {// TODO 自動生成的方法存根String sql = "SELECT * FROM customer WHERE CUST_ID = ?";Connection conn = null;try {conn = dataSource.getConnection();PreparedStatement ps = conn.prepareStatement(sql);ps.setInt(1, custId);Customer customer = null;ResultSet rs = ps.executeQuery();if (rs.next()) {customer = new Customer(rs.getInt("CUST_ID"), rs.getString("NAME"), rs.getInt("Age"));}rs.close();ps.close();return customer;} catch (SQLException e) {throw new RuntimeException(e);} finally {if (conn != null) {try {conn.close();} catch (SQLException e) {}}}}public void setDataSource(DataSource dataSource) {this.dataSource = dataSource;}@Overridepublic List<Customer> queryCustomer() throws Exception {// TODO 自動生成的方法存根Connection conn = dataSource.getConnection();String sql = "Select c.CUST_ID, c.NAME, c.AGE from customer c";System.out.println(sql);Statement smt = conn.createStatement();ResultSet rs = smt.executeQuery(sql);List<Customer> list = new ArrayList<Customer>();while (rs.next()) {int cID = rs.getInt("CUST_ID");String cName = rs.getString("NAME");int cAge = rs.getInt("AGE");Customer cust = new Customer(cID, cName, cAge);list.add(cust);}return list;}}

配置文件spring-dao.xml ?spring-datasource.xml ?spring-module.xml都放置在(特別重要)包com.yiibai.springjdbc下面:

spring-datasource.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"><bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver" /><property name="url" value="jdbc:mysql://localhost:3306/yiibai?useSSL=false" /><property name="username" value="your-user" /><property name="password" value="your-passwd" /></bean></beans>

也可以使用DBCP連接池來配置數據源(需要導入commons-dbcp-1.4.jar包)

   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">        <property name="driverClassName" value="com.mysql.jdbc.Driver" />       <property name="url" value="jdbc:mysql://localhost:3306/yiibai?useSSL=false" />       <property name="username" value="your-name" />       <property name="password" value="your-passwd" />       </bean>

這里需要修改用戶密碼來適應你的數據庫環境

spring-dao.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"><bean id="customerDAO" class="com.yiibai.springjdbc.daoimpl.CustomerImplDAO"><property name="dataSource" ref="dataSource" /></bean></beans>

spring-module.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"><!-- Using Mysql datasource --><import resource="spring-datasource.xml" /><import resource="spring-dao.xml" /></beans>

測試(主)類

package com.yiibai.springjdbc;import java.util.List;import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;import com.yiibai.springjdbc.bean.Customer;
import com.yiibai.springjdbc.dao.CustomerDAO;public class CustTest {private static ApplicationContext ctx;public static void main(String[] args) throws Exception {ctx = new ClassPathXmlApplicationContext("com/yiibai/springjdbc/spring-module.xml");CustomerDAO customerDAO = (CustomerDAO) ctx.getBean("customerDAO");Customer customer = new Customer(1, "yiibai",29);customerDAO.insert(customer);Customer customer1 = customerDAO.findByCustomerId(1);System.out.println(customer1);List<Customer> custList = customerDAO.queryCustomer();for(Customer cs : custList){System.out.println("Customer ID " + cs.getCustId());System.out.println("Customer Name " + cs.getName());System.out.println("Customer Age" + cs.getAge());System.out.println("----------------------------");}}}

運行結果:表customer加了一條記錄,并輸出如下信息:

(執行前把表customer中id為1的記錄刪除,不然插入異常)

三、使用 JdbcTemplate、JdbcDaoSupport實現

Customer和DAO接口不變,主要變化是DAO實現:CustomerImplDAO類改為JdbcCustomerDAO

package com.yiibai.springjdbc.daoimpl;import java.util.List;import org.springframework.jdbc.core.support.JdbcDaoSupport;import com.yiibai.springjdbc.bean.Customer;
import com.yiibai.springjdbc.bean.CustomerRowMapper;
import com.yiibai.springjdbc.dao.CustomerDAO;public class JdbcCustomerDAO extends JdbcDaoSupport implements CustomerDAO {@Overridepublic void insert(Customer customer) {// TODO 自動生成的方法存根String sql = "INSERT INTO customer " +"(CUST_ID, NAME, AGE) VALUES (?, ?, ?)";getJdbcTemplate().update(sql, new Object[] { customer.getCustId(),customer.getName(),customer.getAge()  });}@Overridepublic Customer findByCustomerId(int custId) {// TODO 自動生成的方法存根/** 	這種寫法也可以	String sql = "SELECT * FROM customer WHERE CUST_ID =  '"+custId+"' ";return getJdbcTemplate().queryForObject(sql,new CustomerRowMapper());*/String sql = "SELECT * FROM customer WHERE CUST_ID = ?";return getJdbcTemplate().queryForObject(sql,new Object[] { custId },new CustomerRowMapper());}@Overridepublic List<Customer> queryCustomer() throws Exception {// TODO 自動生成的方法存根String sql = "SELECT * FROM customer";return getJdbcTemplate().query(sql, new CustomerRowMapper());}}

需要說明2點:

1、本實現繼承JdbcDaoSupport,而 JdbcDaoSupport定義了 JdbcTemplate和DataSource 屬性,只需在配置文件中注入DataSource 即可,然后會創建jdbcTemplate的實例,不必像前面的實現CustomerImplDAO那樣,需要顯式定義一個DataSource成員變量。

2、這里出現了CustomerRowMapper類:本來應該這樣寫的queryForObject(sql,Customer.class);但Spring并不知道如何將結果轉成Customer.class。所以需要寫一個CustomerRowMapper?繼承RowMapper接口?,其代碼如下:

package com.yiibai.springjdbc.bean;import java.sql.ResultSet;
import java.sql.SQLException;import org.springframework.jdbc.core.RowMapper;public class CustomerRowMapper implements RowMapper<Customer> {@Overridepublic Customer mapRow(ResultSet rs, int rowNum) throws SQLException {// TODO 自動生成的方法存根return new Customer(rs.getInt("CUST_ID"),rs.getString("NAME"),rs.getInt("AGE"));}}

文件spring-dao.xml里bean的定義修改為(變化的是class):

    <bean id="customerDAO" class="com.yiibai.springjdbc.daoimpl.JdbcCustomerDAO"><property name="dataSource" ref="dataSource" /></bean>

其他配置文件和主類都不變、運行結果少了Select c.CUST_ID, c.NAME, c.AGE from customer c
,這是因為CustomerImplDAO版本人為地插入一句?System.out.println(sql);以示和JDBC模板實現版本JdbcCustomerDAO的區別。
可以看出采用JDBC模板大大簡化代碼。

四、??HibernateTemplate、HibernateDaoSupport實現版本

CustomerImplDAO類改為HibCustomerDao

package com.yiibai.springjdbc.daoimpl;import java.util.List;import org.springframework.orm.hibernate4.support.HibernateDaoSupport;
import com.yiibai.springjdbc.bean.Customer;
import com.yiibai.springjdbc.dao.CustomerDAO;public class HibCustomerDao extends HibernateDaoSupport implements CustomerDAO {@Overridepublic void insert(Customer customer) {// TODO 自動生成的方法存根this.getHibernateTemplate().save(customer);}@Overridepublic Customer findByCustomerId(int custId) {// TODO 自動生成的方法存根//或find("from Customer where CUST_ID = ?",custId).get(0);return (Customer) getHibernateTemplate().get(Customer.class, custId);}@Overridepublic List<Customer> queryCustomer() throws Exception {// TODO 自動生成的方法存根return (List<Customer>) getHibernateTemplate().find("from com.yiibai.springjdbc.bean.Customer"); 	}}

配置文件修改就比較復雜了:要配置SessionFactory、transactionManager、transactionInterceptor等。

,另外要在包com.yiibai.springjdbc.bean增加表對象Customer的Hibernate映射文件Customer.hbm.xml以供配置hibernate SessionFactory使用:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN""http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.yiibai.springjdbc.bean"><class name="Customer" table="customer"><id name="custId" type="java.lang.Integer"><column name="CUST_ID" /><generator class="native"/></id><property name="name" unique="true" type="java.lang.String"><column name="NAME" />	</property><property name="age" unique="true" type="java.lang.Integer"><column name="AGE" />	</property>	</class>
</hibernate-mapping>

修改后的spring-dao.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"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util.xsdhttp://www.springframework.org/schema/toolhttp://www.springframework.org/schema/tool/spring-tool.xsd"><!-- 把數據源注入給Session工廠 --><bean id="custsessionFactory"class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"><property name="dataSource" ref="dataSource1" /><property name="mappingResources"><list><value>com/yiibai/springjdbc/bean/Customer.hbm.xml</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">${hibernate.dialect}</prop><prop key="hibernate.hbm2ddl.auto">update</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.generate_statistics">true</prop><prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop></props></property></bean><!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --><bean id="transactionManager"class="org.springframework.orm.hibernate4.HibernateTransactionManager"><property name="sessionFactory" ref="custsessionFactory" /></bean><!--define bean of transaction interceptor --><bean id="transactionInterceptor"class="org.springframework.transaction.interceptor.TransactionInterceptor"><property name="transactionManager" ref="transactionManager" /><property name="transactionAttributes"><props><prop key="delete*">PROPAGATION_REQUIRED</prop><prop key="update*">PROPAGATION_REQUIRED</prop><prop key="save*">PROPAGATION_REQUIRED,-Exception</prop><prop key="find*">PROPAGATION_REQUIRED,readOnly</prop><prop key="*">PROPAGATION_REQUIRED</prop></props></property></bean><beanclass="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"><property name="beanNames"><list><value>*Dao</value></list></property><property name="interceptorNames"><list><value>transactionInterceptor</value></list></property></bean><bean id="customerDAO" class="com.yiibai.springjdbc.daoimpl.HibCustomerDao">  <property name="sessionFactory" ref="custsessionFactory" /></bean>  </beans>

如果僅配置SessionFactory、而不配置transactionManager、transactionInterceptor,查詢沒問題,而插入不行,會出現下面的異常:

Exception in thread "main" org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

有沒有辦修改SessionFactory的設置解決這個問題,求高人指點。

hibernate配置也可以用注解方式(無需Customer.hbm.xml):

修改Customer類如下(?custId必須要改CUST_ID,和表格字段名完全一致):

package com.yiibai.springjdbc.bean;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;@Entity
@Table(name = "customer")
public class Customer {@Idint CUST_ID;String name;int age;public Customer() {super();// TODO 自動生成的構造函數存根}public Customer(int custId, String name, int age) {super();this.CUST_ID = custId;this.name = name;this.age = age;}public int getCustId() {return CUST_ID;}public void setCustId(int custId) {this.CUST_ID = custId;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Customer [custId=" + CUST_ID + ", name=" + name + ", age=" + age + "]";}
}

spring-dao.xml文件的custsessionFactory配置中

		<property name="mappingResources"><list><value>com/yiibai/springjdbc/bean/Customer.hbm.xml</value></list></property>

改為:

 	<property name="annotatedClasses"><list><value>com.yiibai.springjdbc.bean.Customer</value></list></property>

另外經實踐.hbm.xml版本(注射方式則不會,我也沒搞明白其中的道理)的CUST_ID不是根據insert(customer)傳遞過來參數的值,而是會根據數據庫表customer當前的ID“指針”;比如傳遞過來的參數是Customer(1, "yiibai",29),插入后有可能變(3, "yiibai",29)。

可用下面命令來復位ID“指針”


mysql> use yiibai;
mysql> ALTER TABLE customer AUTO_INCREMENT=0;

這樣新插入的CUST_ID值就是:最后一條記錄CUST_ID+1。

五、mybatis、SqlSessionDaoSupport版本

? ? ? ? 為了簡單起見,使用注解方式使用mybatis(和XML配置可以混用的,詳見該文),重寫了dao接口放在com.yiibai.springjdbc.mybatisdao包下,為保證主類代碼不變原來的接口CustomerDAO繼續使用。

package com.yiibai.springjdbc.mybatisdao;import java.util.List;import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;import com.yiibai.springjdbc.bean.Customer;public interface ICustomer {@Insert("insert into customer(CUST_ID,name,age) values(#{CUST_ID},#{name}, #{age})")public void insert(Customer customer);@Select("select * from customer where CUST_ID= #{CUST_ID}")public Customer findByCustomerId(int custId);@Select("select * from customer")public List<Customer> queryCustomer();@Delete("delete from customer where CUST_ID=#{CUST_ID}")public int deleteCustomerById(int id);
}

所有的sql操作由該接口完成,后面的DAO實現類MybatisCustImpDao,實際上僅僅調用該接口的方法:

package com.yiibai.springjdbc.daoimpl;import java.util.List;import org.mybatis.spring.support.SqlSessionDaoSupport;import com.yiibai.springjdbc.bean.Customer;
import com.yiibai.springjdbc.dao.CustomerDAO;
import com.yiibai.springjdbc.mybatisdao.ICustomer;public class MybatisCustImpDao extends SqlSessionDaoSupport implements CustomerDAO {@Overridepublic void insert(Customer customer) {// TODO 自動生成的方法存根this.getSqlSession().getMapper(ICustomer.class).insert(customer);;}@Overridepublic Customer findByCustomerId(int custId) {// TODO 自動生成的方法存根return this.getSqlSession().getMapper(ICustomer.class).findByCustomerId(custId);}@Overridepublic List<Customer> queryCustomer() throws Exception {// TODO 自動生成的方法存根return this.getSqlSession().getMapper(ICustomer.class).queryCustomer();}}

mybatis的配置文件mybatiscust.xml放在com.yiibai.springjdbc下

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><typeAliases><typeAlias alias="Customer" type="com.yiibai.springjdbc.bean.Customer" /></typeAliases><environments default="development"><environment id="development"><transactionManager type="JDBC" /><dataSource type="POOLED"><property name="driver" value="com.mysql.jdbc.Driver" /><property name="url" value="jdbc:mysql://127.0.0.1:3306/yiibai?useSSL=false" /><property name="username" value="your-user" /><property name="password" value="your-passwd" /></dataSource></environment></environments><mappers><!-- XML的方式 注冊映射配置文件--><!-- <mapper resource="com/yiibai/springjdbc/bean/CustMybatis.xml" /> --><!--接口的方式  注冊接口--><mapper class="com.yiibai.springjdbc.mybatisdao.ICustomer"/></mappers></configuration>

bean必須注入sqlSessionFactory或sqlSessionTemplate。還是在中spring-dao.xml配置:

	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="configLocation"value="classpath:com/yiibai/springjdbc/mybatiscust.xml" /></bean><bean id="CustomerDao" class="com.yiibai.springjdbc.daoimpl.MybatisCustImpDao"><property name="sqlSessionFactory" ref="sqlSessionFactory" /></bean>

?或

	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="configLocation"value="classpath:com/yiibai/springjdbc/mybatiscust.xml" /></bean><bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate"><constructor-arg ref="sqlSessionFactory" /></bean><bean id="CustomerDao" class="com.yiibai.springjdbc.daoimpl.MybatisCustImpDao"><property name="sqlSessionTemplate" ref="sqlSession" /></bean>

主程序還是不變。

參考:

Spring Mybatis實例SqlSessionDaoSupport混用xml配置和注解

HibernateTemplate、HibernateDaoSupport兩種方法實現增刪

Spring JdbcTemplate+JdbcDaoSupport實例

Spring與Dao-Jdbc模板實現增刪改查

使用Jdbc Template的基本操作步驟

Spring+mybatis的一個簡單例子

spring與mybatis三種整合方法MyBatis中

如何通過繼承SqlSessionDaoSupport來編寫DAO(一)

Spring進行面向切面編程的一個簡單例子

項目的代碼和依賴包都在這里,下后解壓到eclipse的workspace導入選擇import Porojects from File System or Archive。

?

?

轉載于:https://my.oschina.net/u/2245781/blog/1552110

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

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

相關文章

開始使用gradle

前提配置gradle環境 每個gradle構建都是以一個腳本開始的。gradle構建默認的名稱為build.gradle。當在shell中執行gradle命令時&#xff0c;gradle會去尋找為build.gradle文件&#xff0c;如果找不到就會顯示幫助信息。 下面我們以經典的helloworld為例。 1、首先建立一個build…

freecodecamp_freeCodeCamp的新編碼課程現已上線,其中包含1,400個編碼課程和6個開發人員認證

freecodecampFor the past year, our community has been hard at work on a massive new programming curriculum. And now that curriculum is live and out of beta!在過去的一年中&#xff0c;我們的社區一直在努力編寫大量的新編程課程。 現在&#xff0c;該課程已上線并且…

麥克勞林展開式_數學家麥克勞林與牛頓的故事

數學家麥克勞林麥克勞林(Colin Maclaurin1698年2月-1746年6月), 蘇格蘭數學家&#xff0c;麥克勞林是18世紀英國最具有影響的數學家之一。01麥克勞林是一位牧師的兒子&#xff0c;半歲喪父&#xff0c;9歲喪母。由其叔父撫養成人。叔父也是一位牧師。麥克勞林是一個“神童”&am…

html隱藏層點擊顯示不出來,[js+css]點擊隱藏層,點擊另外層不能隱藏原層

1貨幣轉換&#xff0c;下圖顯示了這個程序子只進行簡單的 把元素放在下面的目錄下&#xff0c;在創幣轉換應用程序這個例 所需的界面&#xff0c;包括一些UI組件實例(Button, ComboB 貨幣轉換&#xff0c;下圖顯示了這個程序組件實例(Button, ComboB 貨幣轉換&#xff0c;下圖顯…

Oracle 10.2.0.5 非歸檔current redolog損壞處理一例

操作系統: RHEL5.8 x64數據庫 : Oracle 10.2.0.5.0故障情況:一臺單機曙光PC服務器4塊300G SAS盤&#xff0c;RAID5壞兩塊磁盤&#xff08;服務器面板無故障提示&#xff0c;無人發現&#xff09;&#xff0c;造成RAID5磁盤陣列掛掉&#xff0c;操作系統當機&#xff0c;系統無…

基礎命令

date --help date %T 15:04:58 whatis date date (1) - print or set the system date and timeman date 獲取詳細的命令解釋cd ~/wntlab //新建文件夾 mkdir example //新建文件 touch b c //復制文本內容 cp b c//把 b的內容復制給 c cp b a/ //把 文件b復制…

微信小程序把玩(三十三)Record API

微信小程序把玩&#xff08;三十三&#xff09;Record API 原文:微信小程序把玩&#xff08;三十三&#xff09;Record API其實這個API也挺奇葩的&#xff0c;錄音結束后success不走&#xff0c;complete不走&#xff0c;fail也不走&#xff0c; 不知道是不是因為電腦測試的原因…

leetcode336. 回文對(字典樹)

給定一組 互不相同 的單詞&#xff0c; 找出所有不同 的索引對(i, j)&#xff0c;使得列表中的兩個單詞&#xff0c; words[i] words[j] &#xff0c;可拼接成回文串。 示例 1&#xff1a; 輸入&#xff1a;[“abcd”,“dcba”,“lls”,“s”,“sssll”] 輸出&#xff1a;[[…

html文檔 字符引用,【轉】HTML中常見形如#number;的東西叫做 字符實體引用,簡稱引用,代表一個對應的unicode字符...

【轉】HTML中常見形如number;的東西叫做 字符實體引用&#xff0c;簡稱引用&#xff0c;代表一個對應的unicode字符英文解釋的很清楚&#xff0c;就不翻譯了&#xff0c;自己看&#xff1a;EntitiesCharacter entity references, or entities for short, provide a method of e…

終端打開后-bash_如何爵士化Bash終端-帶有圖片的分步指南

終端打開后-bashby rajaraodv通過rajaraodv In this blog I’ll go over the steps to add Themes, Powerline, fonts, and powerline-gitstatus to make your regular Bash Terminal look beautiful and useful as shown in the picture above.在此博客中&#xff0c;我將介紹…

如何獲取元素在父級div里的位置_關于元素的浮動你了解多少

首先&#xff0c;在介紹什么是浮動之前我們先介紹一下html中元素的普通流布局方式。在普通流中&#xff0c;元素是按照它在 HTML 中的出現的先后順序自上而下依次排列布局的&#xff0c;在排列過程中所有的行內元素水平排列&#xff0c;直到當行被占滿然后換行&#xff0c;塊級…

獲取iOS頂部狀態欄和Navigation的高度

狀態欄的高度 20 [[UIApplication sharedApplication] statusBarFrame].size.height Navigation的高度 44 self.navigationController.navigationBar.frame.size.height 加起來一共是64 轉載于:https://www.cnblogs.com/Free-Thinker/p/6478715.html

Java電商項目-5.內容管理cms系統

目錄 實現加載內容分類樹功能實現內容分類動態添加刪除內容分類節點實現內容分類節點的分頁顯示實現廣告內容的添加實現廣告內容刪除實現廣告內容編輯到Github獲取源碼請點擊此處實現加載內容分類樹功能 注: 往后將不在說編寫遠程服務方法和編寫web模塊等重復語句, 直接用"…

leetcode738. 單調遞增的數字(貪心)

給定一個非負整數 N&#xff0c;找出小于或等于 N 的最大的整數&#xff0c;同時這個整數需要滿足其各個位數上的數字是單調遞增。 &#xff08;當且僅當每個相鄰位數上的數字 x 和 y 滿足 x < y 時&#xff0c;我們稱這個整數是單調遞增的。&#xff09; 示例 1: 輸入: …

MySQL purge 線程

MySQL中purge線程知識&#xff1a;https://dev.mysql.com/doc/refman/5.7/en/innodb-improved-purge-scheduling.htmlInnoDB中delete所做刪除只是標記為刪除的狀態&#xff0c;實際上并沒有刪除掉&#xff0c;因為MVCC機制的存在&#xff0c;要保留之前的版本為并發所使用。最終…

安裝inde.html使用babel,reactjs – 使用Babel Standalone進行單個React組件渲染,僅使用index.html和Component...

Noob與React在這里.我正在玩React.我有一個簡單的組件在我的component.js中呈現.它包含在我的index.html文件中.我在頭部包含了React,ReactDOM和babel的腳本.我只想看到一個div正確渲染.我還沒有使用Node,只是使用React和Babel(使用babel-standalone).我正在使用一個簡單的http…

軟件工程師轉正申請_這是申請軟件工程師工作的4種最佳方法-以及如何使用它們。...

軟件工程師轉正申請by YK Sugi由YK Sugi 這是適用于軟件工程師工作的最佳方法&#xff0c;以及確切的使用方法。 (Here are the best methods for applying to software engineer jobs — and exactly how to use them.) When people think of applying for jobs, they often …

【JS新手教程】LODOP打印復選框選中的任務或頁數

之前的博文&#xff1a;【JS新手教程】LODOP打印復選框選中的內容關于任務&#xff1a;Lodop打印語句最基本結構介紹&#xff08;什么是一個任務&#xff09;關于本文用到的JS的eval方法&#xff1a;JS-JAVASCRIPT的eval()方法該文用的是不同checkbox&#xff0c;對應不同的val…

查詢范圍_企二哥:查詢企業經營范圍的三種方法

一、查詢企業經營范圍的三種方法1. 進經營地的工商局網站,有個“全國企業信用信息公示系統”進去后輸入公司名稱搜索就出來了。2. 有個軟件叫做天眼查&#xff0c;打開天眼查輸入要查詢的公司名稱&#xff0c;就可以搜出來了。不光是經營范圍&#xff0c;還有許多和企業相關的資…

C#用DataTable實現Group by數據統計

http://www.cnblogs.com/sydeveloper/archive/2013/03/29/2988669.html 1、用兩層循環計算&#xff0c;前提條件是數據已經按分組的列排好序的。 DataTable dt new DataTable();dt.Columns.AddRange(new DataColumn[] { new DataColumn("name", typeof(string)), …