create database mybatis;
use mybatis;
CREATE TABLE pets(id INT PRIMARY KEY AUTO_INCREMENT, NAME VARCHAR(20), age INT);
INSERT INTO pets(NAME, age) VALUES('Qiuqiu', 1);
INSERT INTO pets(NAME, age) VALUES('Paoao', 3);
package com.lfqy.domain;
/**
* Created by chengxia on 2019/9/9.
*/
public class Pet {
//实体类的属性和表的字段名称一一对应
private int id;
private String name;
private int age;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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;
}
@Override
public String toString() {
return "Pet [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
package com.lfqy.domain;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.InputStream;
import java.util.List;
import static org.junit.Assert.*;
/**
* Created by chengxia on 2019/9/9.
*/
public class PetTest {
private InputStream in;
private SqlSessionFactory factory;
SqlSession session;
@Before//用于在测试方法执行之前先执行
public void init() throws Exception {
//1.读取主配置文件
in = Resources.getResourceAsStream("Conf.xml");//参数就是配置文件的路径和文件名
//2.创建SqlSessionFactory对象
factory = new SqlSessionFactoryBuilder().build(in);
//3.获得一个sqlSession对象
session = factory.openSession();
}
@After//在测试方法执行之后执行
public void destroy() throws Exception {
in.close();
session.close();
}
/**
* 最终的实现结果是:查询id为1的宠物
* @throws Exception
*/
@Test
public void testMyBatis() throws Exception {
String statement = "com.lfqy.mapping.PetMapper.getPet";//映射sql的标识字符串
//执行查询返回一个唯一user对象的sql
Pet pet = session.selectOne(statement, 1);
System.out.println(pet);
}
}
上面的测试代码运行结果如下:
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
Pet [id=1, name=Qiuqiu, age=1]
Process finished with exit code 0
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
flush privileges;
Where root as your user localhost as your URL and password as your password From:参考连接2
2.2.2 示例2_MyBatis代理模式
基于前面的例子,新增一个代理模式用到的mapper类,如下图:
示例2_MyBatis代理模式
com.lfqy.mapping.PetMapper:
package com.lfqy.mapping;
import com.lfqy.domain.Pet;
/**
* Created by chengxia on 2019/9/10.
*/
public interface PetMapper {
Pet getPet(Integer petId);
}
package com.lfqy.domain;
import com.lfqy.mapping.PetMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.InputStream;
/**
* Created by chengxia on 2019/9/9.
*/
public class PetProxyTest {
private InputStream in;
private SqlSessionFactory factory;
SqlSession session;
PetMapper petMapper;
@Before//用于在测试方法执行之前先执行
public void init() throws Exception {
//1.读取主配置文件
in = Resources.getResourceAsStream("Conf.xml");//参数就是配置文件的路径和文件名
//2.创建SqlSessionFactory对象
factory = new SqlSessionFactoryBuilder().build(in);
//3.获得一个sqlSession对象
session = factory.openSession();
//4.获得一个PetMapper代理对象
petMapper = session.getMapper(PetMapper.class);
}
@After//在测试方法执行之后执行
public void destroy() throws Exception {
in.close();
session.close();
}
/**
* 最终的实现结果是:查询id为1的宠物
* @throws Exception
*/
@Test
public void testMyBatis() throws Exception {
//执行前面得到的动态代理对象Mapper对象的getPet方法
Pet pet = petMapper.getPet(1);
System.out.println(pet);
}
}
运行结果如下:
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
Pet [id=1, name=Qiuqiu, age=1]
Process finished with exit code 0
package com.lfqy.mapping;
import com.lfqy.domain.Pet;
import org.apache.ibatis.annotations.Select;
/**
* Created by chengxia on 2019/9/10.
*/
public interface PetAnnotationMapper {
@Select("select * from pets where id=#{id}")
Pet getPet(Integer petId);
}
package com.lfqy.domain;
import com.lfqy.mapping.PetAnnotationMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.InputStream;
/**
* Created by chengxia on 2019/9/9.
*/
public class PetProxyAnnotationTest {
private InputStream in;
private SqlSessionFactory factory;
SqlSession session;
PetAnnotationMapper petMapper;
@Before//用于在测试方法执行之前先执行
public void init() throws Exception {
//1.读取主配置文件
in = Resources.getResourceAsStream("Conf.xml");//参数就是配置文件的路径和文件名
//2.创建SqlSessionFactory对象
factory = new SqlSessionFactoryBuilder().build(in);
//3.获得一个sqlSession对象
session = factory.openSession();
//4.获得一个PetMapper代理对象
petMapper = session.getMapper(PetAnnotationMapper.class);
}
@After//在测试方法执行之后执行
public void destroy() throws Exception {
in.close();
session.close();
}
/**
* 最终的实现结果是:查询id为1的宠物
* @throws Exception
*/
@Test
public void testMyBatis() throws Exception {
//执行前面得到的动态代理对象Mapper对象的getPet方法
Pet pet = petMapper.getPet(1);
System.out.println(pet);
}
}
运行结果如下:
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
Pet [id=1, name=Qiuqiu, age=1]
Process finished with exit code 0
package com.lfqy.domain;
/**
* Created by chengxia on 2019/9/16.
*/
public class Pet {
//实体类的属性和表的字段名称一一对应
private int id;
private String name;
private int age;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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;
}
@Override
public String toString() {
return "Pet [id=" + id + ", name=" + name + ", age=" + age + "]";
}
}
package com.lfqy.dao;
import com.lfqy.domain.Pet;
import java.util.List;
/**
* Created by chengxia on 2019/9/10.
*/
public interface PetMapper {
List getPets(Integer petId);
}
com.lfqy.dao.PetAnnotationMapper:
package com.lfqy.dao;
import com.lfqy.domain.Pet;
import com.lfqy.mybatis.annotations.Select;
import java.util.List;
/**
* Created by chengxia on 2019/9/10.
*/
public interface PetAnnotationMapper {
//由于这里基于注解的实现中,省略了参数解析的部分,这里直接写死参数
@Select("select * from pets where id=2")
List getPets(Integer petId);
}
九月 16, 2019 1:33:36 上午 com.mchange.v2.log.MLog
信息: MLog clients using java 1.4+ standard logging.
九月 16, 2019 1:33:41 上午 com.mchange.v2.c3p0.C3P0Registry banner
信息: Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
九月 16, 2019 1:33:43 上午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge13aa5ez9jhd1irjrim|3a82f6ef, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge13aa5ez9jhd1irjrim|3a82f6ef, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf8, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
Mon Sep 16 01:33:43 CST 2019 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 Sep 16 01:33:43 CST 2019 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 Sep 16 01:33:43 CST 2019 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.
=========com.lfqy.dao.PetMapper.getPets==========
Pet [id=1, name=Qiuqiu, age=1]
九月 16, 2019 1:33:48 上午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
信息: Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1hge13aa5ez9jhd1irjrim|2d8f65a4, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge13aa5ez9jhd1irjrim|2d8f65a4, idleConnectionTestPeriod -> 0, initialPoolSize -> 3, jdbcUrl -> jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf8, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> null, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
Mon Sep 16 01:33:48 CST 2019 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 Sep 16 01:33:48 CST 2019 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 Sep 16 01:33:48 CST 2019 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.
=========com.lfqy.dao.PetAnnotationMapper.getPets==========
Pet [id=2, name=Paoao, age=3]
Process finished with exit code 0
声明: 本文只为方便我个人查阅和理解,详细的分析以及源代码请移步 原作者的博客http://chjavach.iteye.com/
public class Singleton {
}
/*
* 懒汉模式。注意,getInstance如果在多线程环境中调用,需要加上synchronized,否则存在线程不安全问题
*/
class LazySingleton
这个月公司安排我一个人做iOS客户端开发,由于急着用,我先发布一个版本,由于第一次发布iOS应用,期间出了不少问题,记录于此。
1、使用Application Loader 发布时报错:Communication error.please use diagnostic mode to check connectivity.you need to have outbound acc
/*
2013年3月15日15:16:24
malloc 就memory(内存) allocate(分配)的缩写
本程序没有实际含义,只是理解使用
*/
# include <stdio.h>
# include <malloc.h>
int main(void)
{
int i = 5; //分配了4个字节 静态分配
int * p
http://wiki.sdn.sap.com/wiki/display/BOBJ/Optimize+query+with+Query+Stripping+in+Web+Intelligence
and a very straightfoward video
http://www.sdn.sap.com/irj/scn/events?rid=/library/uuid/40ec3a0c-936