HibernateTemplate

org.springframework.orm.hibernate5.HibernateTemplate

这是spring-orm-4.3.4.RELEASE.jar包中的一个类,这个类是对Hibernate进行了封装;

这是可以进行注入的属性,需要注入sessionFactory属性,因此我们需要创建一个sessionFactory的Bean:

    <bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate"><property name="sessionFactory" ref=""></property></bean>

创建sessionFactory需要用到

org.springframework.orm.hibernate5.LocalSessionFactoryBean

这是spring-orm-4.3.4.RELEASE.jar包中的类

可注入的属性有:

 将sessionFactory注入到hibernateTemplate中:

 1     <bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
 2         <property name="sessionFactory" ref="sessionFactory"></property>
 3     </bean>
 4     <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
 5         <property name="dataSource" ref="需要注入数据源"></property>
 6         <property name="hibernateProperties">
 7             <props>
 8                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
 9                 <prop key="hibernate.show_sql">true</prop>
10                 <prop key="hibernate.format_sql">true</prop>
11                 <prop key="hibernate.hbm2ddl.auto">update</prop>            
12                 <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>            
13             </props>
14         </property>
15         <property name="packagesToScan">
16             <array>
17                 <value>需要扫描的包</value>
18             </array>
19         </property>
20     </bean>
sessionFactory

 

创建sessionFactory还需要加载数据源和hibernate映射类的包;

    <bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource"><property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property><property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&amp;useSSL=false"></property><property name="user" value="root"></property><property name="password" value="zhangpn"></property>    

创建基类:

  1 package com.zhangpn.domain;
  2 
  3 import java.io.Serializable;
  4 
  5 import javax.persistence.Column;
  6 import javax.persistence.Entity;
  7 import javax.persistence.GeneratedValue;
  8 import javax.persistence.GenerationType;
  9 import javax.persistence.Id;
 10 import javax.persistence.Table;
 11 
 12 /**
 13  * 客户基类
 14  * 
 15  * @author Administrator
 16  *
 17  */
 18 
 19 @Entity
 20 @Table(name="cst_customer")
 21 public class Customer implements Serializable {
 22 
 23     @Id
 24     @Column(name="cust_id")
 25     @GeneratedValue(strategy=GenerationType.IDENTITY)
 26     private Long custId;
 27     
 28     @Column(name="cust_name")
 29     private String custName;
 30     
 31     @Column(name="cust_source")
 32     private String custSource;
 33     
 34     @Column(name="cust_industry")
 35     private String custIndustry;
 36     
 37     @Column(name="cust_level")
 38     private String custLevel;
 39     
 40     @Column(name="cust_address")
 41     private String custAddress;
 42     
 43     @Column(name="cust_phone")
 44     private String custPhone;
 45 
 46     public Long getCustId() {
 47         return custId;
 48     }
 49 
 50     public void setCustId(Long custId) {
 51         this.custId = custId;
 52     }
 53 
 54     public String getCustName() {
 55         return custName;
 56     }
 57 
 58     public void setCustName(String custName) {
 59         this.custName = custName;
 60     }
 61 
 62     public String getCustSource() {
 63         return custSource;
 64     }
 65 
 66     public void setCustSource(String custSource) {
 67         this.custSource = custSource;
 68     }
 69 
 70     public String getCustIndustry() {
 71         return custIndustry;
 72     }
 73 
 74     public void setCustIndustry(String custIndustry) {
 75         this.custIndustry = custIndustry;
 76     }
 77 
 78     public String getCustLevel() {
 79         return custLevel;
 80     }
 81 
 82     public void setCustLevel(String custLevel) {
 83         this.custLevel = custLevel;
 84     }
 85 
 86     public String getCustAddress() {
 87         return custAddress;
 88     }
 89 
 90     public void setCustAddress(String custAddress) {
 91         this.custAddress = custAddress;
 92     }
 93 
 94     public String getCustPhone() {
 95         return custPhone;
 96     }
 97 
 98     public void setCustPhone(String custPhone) {
 99         this.custPhone = custPhone;
100     }
101 
102     @Override
103     public String toString() {
104         return "Customer [custId=" + custId + ", custName=" + custName + ", custSource=" + custSource
105                 + ", custIndustry=" + custIndustry + ", custLevel=" + custLevel + ", custAddress=" + custAddress
106                 + ", custPhone=" + custPhone + "]";
107     }
108 
109 }
Customer基类

将packagesToScan属性进行注入,最终的applicationContext.xml内容是:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
 5 
 6     <bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
 7         <property name="sessionFactory" ref="sessionFactory"></property>
 8     </bean>
 9     <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
10         <property name="dataSource" ref="datasource"></property>
11         <property name="hibernateProperties">
12             <props>
13                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
14                 <prop key="hibernate.show_sql">true</prop>
15                 <prop key="hibernate.format_sql">true</prop>
16                 <prop key="hibernate.hbm2ddl.auto">update</prop>            
17                 <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>            
18             </props>
19         </property>
20         <property name="packagesToScan">
21             <array>
22                 <value>com.zhangpn.domain</value>
23             </array>
24         </property>
25     </bean>
26     <bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
27         <property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property>
28         <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&amp;useSSL=false"></property>
29         <property name="user" value="root"></property>
30         <property name="password" value="zhangpn"></property>    
31     </bean>
32 </beans>
applicationContext.xml

再将事务管理配置:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:tx="http://www.springframework.org/schema/tx"
 5     xmlns:context="http://www.springframework.org/schema/context"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 7         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
 8         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
 9 
10     <bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
11         <property name="sessionFactory" ref="sessionFactory"></property>
12     </bean>
13     <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
14         <property name="dataSource" ref="datasource"></property>
15         <property name="hibernateProperties">
16             <props>
17                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
18                 <prop key="hibernate.show_sql">true</prop>
19                 <prop key="hibernate.format_sql">true</prop>
20                 <prop key="hibernate.hbm2ddl.auto">update</prop>            
21                 <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>            
22             </props>
23         </property>
24         <property name="packagesToScan">
25             <array>
26                 <value>com.zhangpn.domain</value>
27             </array>
28         </property>
29     </bean>
30     <bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
31         <property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property>
32         <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT&amp;useSSL=false"></property>
33         <property name="user" value="root"></property>
34         <property name="password" value="zhangpn"></property>    
35     </bean>
36     <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
37         <property name="sessionFactory" ref="sessionFactory"></property>
38     </bean>
39     <tx:annotation-driven transaction-manager="transactionManager"/>    
40 </beans>
applicationContext.xml

(中间jdbcUrl有点小错误影响不大,修改过后以下是最终applicationContext.xml配置)

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:tx="http://www.springframework.org/schema/tx"
 5     xmlns:context="http://www.springframework.org/schema/context"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 7         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
 8         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
 9 <!-- Spring容器创建,扫描的包 -->
10     <context:component-scan base-package="com.zhangpn.*"></context:component-scan>
11 
12     <bean id="hibernateTemplate" class="org.springframework.orm.hibernate5.HibernateTemplate">
13         <property name="sessionFactory" ref="sessionFactory"></property>
14     </bean>
15     <bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
16         <property name="dataSource" ref="datasource"></property>
17         <property name="hibernateProperties">
18             <props>
19                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
20                 <prop key="hibernate.show_sql">true</prop>
21                 <prop key="hibernate.format_sql">true</prop>
22                 <prop key="hibernate.hbm2ddl.auto">update</prop>            
23                 <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>            
24             </props>
25         </property>
26         <property name="packagesToScan">
27             <array>
28                 <value>com.zhangpn.domain</value>
29             </array>
30         </property>
31     </bean>
32     <bean id="datasource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
33         <property name="driverClass" value="com.mysql.cj.jdbc.Driver"></property>
34         <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/ssh?serverTimezone=GMT"></property>
35         <property name="user" value="root"></property>
36         <property name="password" value="zhangpn"></property>    
37     </bean>
38     <bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
39         <property name="sessionFactory" ref="sessionFactory"></property>
40     </bean>
41     <tx:annotation-driven transaction-manager="transactionManager"/>    
42 </beans>
applicationContext.xml

测试主方法:

 1 package com.zhangpn.Test;
 2 
 3 import java.util.Iterator;
 4 import java.util.List;
 5 
 6 import org.hibernate.criterion.DetachedCriteria;
 7 import org.springframework.context.ApplicationContext;
 8 import org.springframework.context.support.ClassPathXmlApplicationContext;
 9 import org.springframework.orm.hibernate5.HibernateTemplate;
10 
11 import com.zhangpn.domain.Customer;
12 
13 public class Test {
14 
15     public static void main(String[] args) {
16         ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
17         HibernateTemplate hibernateTemplate = (HibernateTemplate) applicationContext.getBean("hibernateTemplate");
18         DetachedCriteria dCriteria = DetachedCriteria.forClass(Customer.class);
19         List<Customer> customers = (List<Customer>) hibernateTemplate.findByCriteria(dCriteria);
20         for (Customer customer : customers) {
21             System.out.println(customer);
22         }
23     }
24 
25 }
测试类

主要代码:

    public static void main(String[] args) {ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");HibernateTemplate hibernateTemplate = (HibernateTemplate) applicationContext.getBean("hibernateTemplate");DetachedCriteria dCriteria = DetachedCriteria.forClass(Customer.class);List<Customer> customers = (List<Customer>) hibernateTemplate.findByCriteria(dCriteria);for (Customer customer : customers) {System.out.println(customer);}}

最终,可以将数据库中的信息查询出来;

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Mon Jun 11 12:01:45 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mon Jun 11 12:01:45 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Mon Jun 11 12:01:45 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
Hibernate: selectthis_.cust_id as cust_id1_0_0_,this_.cust_address as cust_add2_0_0_,this_.cust_industry as cust_ind3_0_0_,this_.cust_level as cust_lev4_0_0_,this_.cust_name as cust_nam5_0_0_,this_.cust_phone as cust_pho6_0_0_,this_.cust_source as cust_sou7_0_0_ fromcst_customer this_
Customer [custId=1, custName=张沛宁, custSource=1, custIndustry=长亮科技, custLevel=88级, custAddress=沛高中, custPhone=13613641361]
Customer [custId=2, custName=张沛龙, custSource=2, custIndustry=黑马科技, custLevel=45级, custAddress=沛高中, custPhone=13644441361]
Customer [custId=3, custName=刘晓云, custSource=3, custIndustry=瑞士科技, custLevel=55级, custAddress=徐一中, custPhone=13618582361]
Customer [custId=4, custName=zhangpn, custSource=5, custIndustry=American, custLevel=90, custAddress=江苏徐州, custPhone=13654874562]
Customer [custId=5, custName=小白, custSource=7, custIndustry=大学城, custLevel=20级, custAddress=常州大学, custPhone=13655479541]
Customer [custId=6, custName=zhangpn, custSource=5, custIndustry=American, custLevel=90, custAddress=刘德华, custPhone=13654874562]
Customer [custId=7, custName=44, custSource=666, custIndustry=22, custLevel=33, custAddress=11, custPhone=55]
Customer [custId=8, custName=搭建了, custSource=框架, custIndustry=你, custLevel=已经成功地, custAddress=恭喜, custPhone=SSH]

 findByCriteria方法:有两个用法;

第一种方法,不能分页;第二种方法,可以分页;

 findByCriteria意思是按照一定的标准去查找;那么这个标准是什么?我们怎么去定义这个标准?

答案是:Restrictions类


下面是 Restrictions的静态方法


 

举一个简单的例子:从表中查询custId为 5 的记录;

限制Restrictions定为:

Restrictions.eq("custId", 5L)

 

作为参数 :

    public static void main(String[] args) {ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");HibernateTemplate hibernateTemplate = (HibernateTemplate) applicationContext.getBean("hibernateTemplate");DetachedCriteria dCriteria = DetachedCriteria.forClass(Customer.class); dCriteria.add(Restrictions.eq("custId", 5L));List<Customer> customers = (List<Customer>) hibernateTemplate.findByCriteria(dCriteria);for (Customer customer : customers) {System.out.println(customer);}}

 

 执行后结果:

Hibernate: selectthis_.cust_id as cust_id1_0_0_,this_.cust_address as cust_add2_0_0_,this_.cust_industry as cust_ind3_0_0_,this_.cust_level as cust_lev4_0_0_,this_.cust_name as cust_nam5_0_0_,this_.cust_phone as cust_pho6_0_0_,this_.cust_source as cust_sou7_0_0_ fromcst_customer this_ wherethis_.cust_id=?
Customer [custId=5, custName=小白, custSource=7, custIndustry=大学城, custLevel=20级, custAddress=常州大学, custPhone=13655479541]

 

 查询出来了!


 

如果查询多个条件,怎么办?

比如查询custSource=5并且custIndustry为“American”的记录:

 1     public static void main(String[] args) {
 2         ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
 3         HibernateTemplate hibernateTemplate = (HibernateTemplate) applicationContext.getBean("hibernateTemplate");
 4         
 5         DetachedCriteria dCriteria = DetachedCriteria.forClass(Customer.class);
 6         
 7         dCriteria.add(Restrictions.eq("custSource", "5")).add(Restrictions.eq("custIndustry", "American"));
 8         
 9         List<Customer> customers = (List<Customer>) hibernateTemplate.findByCriteria(dCriteria);
10         
11         for (Customer customer : customers) {
12             System.out.println(customer);
13         }
14     }

 

 运行结果:

Hibernate: selectthis_.cust_id as cust_id1_0_0_,this_.cust_address as cust_add2_0_0_,this_.cust_industry as cust_ind3_0_0_,this_.cust_level as cust_lev4_0_0_,this_.cust_name as cust_nam5_0_0_,this_.cust_phone as cust_pho6_0_0_,this_.cust_source as cust_sou7_0_0_ fromcst_customer this_ wherethis_.cust_source=? and this_.cust_industry=?
Customer [custId=4, custName=zhangpn, custSource=5, custIndustry=American, custLevel=90, custAddress=江苏徐州, custPhone=13654874562]
Customer [custId=6, custName=zhangpn, custSource=5, custIndustry=American, custLevel=90, custAddress=刘德华, custPhone=13654874562]

 

 


findByCriteria的另一种用法:

先看一下总记录:

Customer [custId=1, custName=张沛宁, custSource=1, custIndustry=长亮科技, custLevel=88级, custAddress=沛高中, custPhone=13613641361]
Customer [custId=2, custName=张沛龙, custSource=2, custIndustry=黑马科技, custLevel=45级, custAddress=沛高中, custPhone=13644441361]
Customer [custId=3, custName=刘晓云, custSource=3, custIndustry=瑞士科技, custLevel=55级, custAddress=徐一中, custPhone=13618582361]
Customer [custId=4, custName=zhangpn, custSource=5, custIndustry=American, custLevel=90, custAddress=江苏徐州, custPhone=13654874562]
Customer [custId=5, custName=小白, custSource=7, custIndustry=大学城, custLevel=20级, custAddress=常州大学, custPhone=13655479541]
Customer [custId=6, custName=zhangpn, custSource=5, custIndustry=American, custLevel=90, custAddress=刘德华, custPhone=13654874562]
Customer [custId=7, custName=44, custSource=666, custIndustry=22, custLevel=33, custAddress=11, custPhone=55]
Customer [custId=8, custName=搭建了, custSource=框架, custIndustry=你, custLevel=已经成功地, custAddress=恭喜, custPhone=SSH]

 

 第一个参数大家都肯定懂了吧,第二个和第三个分别是:开始位置 和 查询个数

List<Customer> customers = (List<Customer>) hibernateTemplate.findByCriteria(dCriteria,0,3);

 

(dCriteria,0,3);意思就是按照约束标准从第0个开始查询,查询3条记录;执行后结果预计是前三条记录,我们来看一下:
测试源码:
 1 package com.zhangpn.Test;
 2 
 3 import java.util.List;
 4 
 5 import org.hibernate.criterion.DetachedCriteria;
 6 import org.springframework.context.ApplicationContext;
 7 import org.springframework.context.support.ClassPathXmlApplicationContext;
 8 import org.springframework.orm.hibernate5.HibernateTemplate;
 9 
10 import com.zhangpn.domain.Customer;
11 
12 public class Test {
13 
14     public static void main(String[] args) {
15         ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
16         HibernateTemplate hibernateTemplate = (HibernateTemplate) applicationContext.getBean("hibernateTemplate");
17         
18         DetachedCriteria dCriteria = DetachedCriteria.forClass(Customer.class);
19         
20         //List<Customer> customers = (List<Customer>) hibernateTemplate.findByCriteria(dCriteria);
21         List<Customer> customers = (List<Customer>) hibernateTemplate.findByCriteria(dCriteria,0,3);
22         
23         for (Customer customer : customers) {
24             System.out.println(customer);
25         }
26     }
27 
28 }
测试源码

 

 测试结果:

 1 log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
 2 log4j:WARN Please initialize the log4j system properly.
 3 log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
 4 Mon Jun 11 12:42:28 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
 5 Mon Jun 11 12:42:28 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
 6 Mon Jun 11 12:42:28 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
 7 Hibernate: 
 8     select
 9         this_.cust_id as cust_id1_0_0_,
10         this_.cust_address as cust_add2_0_0_,
11         this_.cust_industry as cust_ind3_0_0_,
12         this_.cust_level as cust_lev4_0_0_,
13         this_.cust_name as cust_nam5_0_0_,
14         this_.cust_phone as cust_pho6_0_0_,
15         this_.cust_source as cust_sou7_0_0_ 
16     from
17         cst_customer this_ limit ?
18 Customer [custId=1, custName=张沛宁, custSource=1, custIndustry=长亮科技, custLevel=88级, custAddress=沛高中, custPhone=13613641361]
19 Customer [custId=2, custName=张沛龙, custSource=2, custIndustry=黑马科技, custLevel=45级, custAddress=沛高中, custPhone=13644441361]
20 Customer [custId=3, custName=刘晓云, custSource=3, custIndustry=瑞士科技, custLevel=55级, custAddress=徐一中, custPhone=13618582361]

 

 果然是3条记录,没毛病!


 

 更多的内容可以自己去尝试着测试,关键是环境要搭建好!

转载于:https://www.cnblogs.com/batj/p/9166303.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/353504.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

使用电脑无线网卡分享网络命令

netsh wlan set hostednetwork modeallow ssidYourWifiName keyYourWifiPasswordnetsh wlan start hostednetworknetsh wlan show hostednetworkpause

STL_queue

STL__queue_的应用 调用的时候要有头文件&#xff1a; #include<stdlib.h> 或 #include<cstdlib> #include<queue> 详细用法: 定义一个queue的变量 queue<Type> que 查看是否为空范例 que.empt…

第四章: 4.1 logging模块 | 正则表达式

修改json数据然后写入json文件中 f open(1234.json,r,encodingutf-8) data f.read() data1 json.loads(data)data1[status] 1f1 open(1234.json,w,encodingutf-8)json.dump(data1,f1) hashlib md5值的用法 #加入下面这个就可以 password input(请输入密码:)m hashlib.md…

Java EE 6 VS Spring 3:Java EE杀死了Spring? 没门!

介绍 几天前&#xff0c;我在听Java Spotlight Podcast的第85集 。 在这次演讲中&#xff0c; Bert Ertman和Paul Bakker讨论了从Spring迁移到Java EE的问题。 基本上&#xff0c;在他们的介绍中&#xff0c;他们说&#xff0c;如今&#xff0c;选择Spring而不是Java EE是没有意…

蓝桥杯 n进制小数

n进制小数 将任意十进制正小数分别转换成2,3,4,5,6,7,8,9进制正小数&#xff0c;小数点后保留8位&#xff0c;并输出。例如&#xff1a;若十进制小数为0.795&#xff0c;则输出&#xff1a; 十进制正小数 0.795000 转换成 2 进制数为: 0.11001011 十进制正小数 0.795000 转换成…

状态栏编程(显示系统时间和进度条)

原文地址&#xff1a;http://welkangm.blog.163.com/blog/static/19065851020127941446182/ 显示系统时间 1、 在状态栏中设置两个新的栏位Timer和Progress。首先到ResourceView中编辑String Table&#xff0c;增加IDS_TIMER(时间),PROGRESS(进度)。然后在MainFrame中修改ind…

使用保险柜管理机密

您如何存储秘密&#xff1f; 密码&#xff0c;API密钥&#xff0c;安全令牌和机密数据属于秘密类别。 那是不应该存在的数据。 在容易猜测的位置&#xff0c;不得以纯文本格式提供。 实际上&#xff0c;不得在任何位置以明文形式存储它。 可以使用Spring Cloud Config Server或…

winScp中文乱码设置

打开一个putty窗口(图一)&#xff0c;左上角鼠标左键点击&#xff0c;弹出设置界面&#xff0c;选择Change Settings&#xff0c;在图二界面的window->translation&#xff0c;Remote character set选择UTF-8&#xff0c;Apply应用即可。 转载于:https://www.cnblogs.com/ya…

键盘布局的改进之道

原文地址&#xff1a;http://www.cppblog.com/huaxiazhihuo/archive/2013/06/29/201380.html好久没上博客了&#xff0c;自己的那么一点微末道行也不敢拿出来丢人现眼。实际上&#xff0c;过去的几年&#xff0c;真的是让C和MFC害惨了&#xff0c;一直自个儿固步自封&#xff0…

如何将二维数组作为函数的参数传递

如何将二维数组作为函数的参数传递声明&#xff1a;如果你是得道的大侠&#xff0c;这篇文章可能浪费你的时间&#xff0c;如果你坚持要看&#xff0c;我当然感觉很高兴&#xff0c;但是希望你看完了别骂我&#xff01;如果你发现我这篇文章有错误的话&#xff0c;你可以提出批…

鼠标爱心显示

/**爱心start**/(function(window,document,undefined){var hearts [];window.requestAnimationFrame (function(){return window.requestAnimationFrame ||window.webkitRequestAnimationFrame ||window.mozRequestAnimationFrame ||window.oRequestAnimationFrame ||window…

多台电脑共用一个耳机、音箱

台式机电脑声卡一般有三个插孔&#xff0c;一个是麦克风&#xff0c;一个是耳机&#xff0c;另一个就是LineIn输入口了&#xff0c;买一根AUX线&#xff0c;一头插入笔记本的耳机插口&#xff0c;另一头插入台式机linein口&#xff1b;在控制面板的声音中选择线路输入&#xff…

liferay开发文档_Liferay –简单主题开发

liferay开发文档实际上&#xff0c;Liferay的6.1版本已经走了很长一段路&#xff0c;该版本完全支持JSF和IceFaces。 我一直在努力学习它的绳索&#xff0c;因为我希望使其成为我们团队中的标准协作工具。 好的软件应用程序可以解决问题&#xff0c;但是好的软件应用程序不仅可…

ACRush 楼天城回忆录

利用假期空闲之时&#xff0c;将这几年 GCJ &#xff0c; ACM &#xff0c; TopCoder 参加的一些重要比赛作个回顾。首先是 GCJ2006 的回忆。 Google Code Jam 2006 一波三折&#xff1a; Google Code Jam 2006 是我第一次到美国参加现场的程序设计比赛。 Google Code Jam 2006…

Matlab计时函数

1. cputime 显示Matlab启动后所占用的CPU时间&#xff1b;eg: t0 cputime; 你的程序&#xff1b;timecputime-t0;2. tic&#xff0c;toc 秒表计时&#xff0c;tic是开始&#xff0c;toc是结束&#xff1b;eg: tic; 你的程序&#xff1b;toc;3. clock&#xff0c;etime 前者显示…

列表,字典表达式以及三元表达式

1.三元表达式条件成立时的返回值 if 条件 else 条件不成立时的返回值三元表达式的意义就是让一些简单的if判断写成一行&#xff0c;减少代码量def max2(x,y): if x > y: return x else: return yx10y20res x if x > y else yprint(res)2.列表生成式…

JUnit 5 –条件

最近&#xff0c;我们了解了JUnit的新扩展模型以及它如何使我们能够将自定义行为注入测试引擎。 我向你保证要看情况。 现在就开始吧&#xff01; 条件允许我们在应该执行或不应该执行测试时定义灵活的标准。 它们的正式名称是“ 条件测试执行” 。 总览 本系列中有关JUnit 5…

我的编程竞赛之路 ——中国大学生计算机编程第一人楼天城访谈

记者/陈秋歌 25岁的楼天城有“中国大学生计算机编程第一人”的称号&#xff0c;也被参加竞赛的学子们敬称为“楼教主”。他的传奇经历一直激励着众多年轻学子&#xff1a;从2001年开始参加计算机编程竞赛&#xff0c;并连获全国一等奖&#xff1b;2004年入选国家集训队&#xf…

MATLAB集合运算

intersect求两个集合的交集ismember检测集合中的元素setdiff求两个集合的差setxor求两个集合交集的非&#xff08;异或&#xff09;union求两个集合的并集unique取集合的单值元素注&#xff1a;交并等操作会对操作结果进行排序

IE8兼容性问题的解决方案

前几天&#xff0c;面试到Ie8的一些兼容问题&#xff0c;傻眼了&#xff0c;回想自己做了将近2年的移动端项目&#xff0c;ie兼容似乎没怎么做过。所以私下便开始找找ie兼容的视频或者文章学习&#xff0c;唉&#xff0c;还是不买书了&#xff0c;家里那么多书&#xff0c;都没…