(一)Mybatis环境配置

概述

  Mybatis是一种半自动化的ORM(Object Relational Mapping)框架,基于JDBC的实现。首先,非常推荐大家先看一下官方使用文档(有中文选择):
http://www.mybatis.org/mybatis-3/zh/index.html
  该文档包含了所有Mybatis的使用方面的配置说明,大家在使用的时候如果不懂一些配置或参数是什么意思,都可以在这里进行查询。

Mybatis了解

  1. Mybatis使用简单的XML配置或者注解将mapper接口与要执行的sql语句进行绑定,绑定完成之后映射成最终要执行的sql语句,执行完sql语句后,为我们自动实现数据库记录与Java实体对象之间的映射。

  2. 通过打印日志我们也可以看到Mybatis打印了全是sql语句,这是因为Mybatis是完全基于JDBC,并且几乎完全消除了JDBC中对参数的手工设置及对结果集的检索。

  3. Mybatis的各种映射关系是通过SqlSession来实现的,顾名思义,就是sql的session会话,在该会话生命周期内,实现对数据库的各种操作。

  4. 在Mybatis中,我们可以编写非常灵活的sql,基于Druid或这种类似的监控管理,我们可以很方便的找到需要优化的sql,从而让sql语句完全控制在我们的手中。但正是由于Mybatis的工作方式,所以有可能会有特别多的sql语句,这偶尔也会成为开发者们头疼的问题。

Mybatis实现详解

  了解了大概的流程之后,我们来看一下大概的配置说明,本文不会深入研究,只是讲一下Mybatis的各种配置的含义,具体与源码的结合将会在下一篇中逐渐开始讲解。

SqlSession

从上面可以知道,Mybatis与数据库打交道全是通过SqlSession来实现的,而SqlSession什么时候创建,又是如何创建的呢。

  1. 通过我们上篇文章中的例子,我们可以看到,没有通过Spring的情况下,使用SqlSession的大致流程如下:
  1. 读取Mybatis的全局配置文件;
  2. 通过SqlSessionFactoryBuilder构建SqlSessionFactory工厂,然后通过SqlSessionFactory创建SqlSession会话;
  3. 然后通过SqlSession进行数据库的各种操作;
  4. 执行完成,关闭sqlSession;
  1. SqlSessionFactoryBuilder目的就是用于创建SqlSessionFactory,他的生命周期很短,就是在初始化的时候才有用。

接下来,我们通过单独配置mybatis和与spring集成mybatis这两种方式来学习一下mybatis的使用。

注:本系列Mybatis代码版本全是基于Mybatis3.4,Spring版本是4,开发工具是idea2017,druid是1.0.20,Junit是4,项目使用maven管理。

Mybatis+Maven管理

1. 表结构:

-- 只有一张简单的表Student,有三个字段,id,name,age
DROP TABLE IF EXISTS `student`;
CREATE TABLE `student` (
  `id` int(10) NOT NULL,
  `name` varchar(32) DEFAULT NULL,
  `age` int(3) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

2. 工程目录:

工程目录

3. pom.xml:只需要引入我们必需的mybatis包和mysql驱动包

<properties>
        <mybatis.version>3.4.0</mybatis.version>
    </properties>
    <dependencies>
        <!-- mybatis 配置 -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>${mybatis.version}</version>
        </dependency>
        <!-- mysql驱动 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.30</version>
        </dependency>
    </dependencies>

Student.java和IStudentMapper.java:

package com.entity;

/**
 * Student实体
 *
 * @author zhangwugui
 * @since 2018/1/24 17:22
 */
public class Student {
    private Integer id;
    private String name;
    private Integer age;
    // get,set省略
    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

//IStudentMapper
package com.mapper;

import com.entity.Student;

import java.util.List;

/**
 * TODO
 *
 * @author zhangwugui
 * @since 2018/1/24 17:28
 */
public interface IStudentMapper {
    List<Student> getAll();

    int save(Student article);

    Student update(Student article);

    int delete(int id);

    Student findStudentById(int id);
}

StudentMapper.xml

<?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="com.mapper.IStudentMapper">
    <select id="getAll" resultType="Student">
        SELECT * FROM Student
    </select>

    <insert id="save" parameterType="Student">
        INSERT INTO Student (id, name, age) VALUES (
          #{id}, #{name}, #{age}
        )
    </insert>

    <update id="update" parameterType="Student">
        UPDATE Student SET
          name = #{name},
          age = #{age}
        WHERE id = #{id}
    </update>

    <delete id="delete" parameterType="int">
        DELETE FROM Student
        WHERE id = #{id}
    </delete>

    <select id="findStudentById" parameterType="int" resultType="Student">
        SELECT * FROM Student
        WHERE id = #{id}
    </select>
</mapper>

mybatis-config.xml

<?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 type="com.entity.Student" alias="Student"/>
    </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://localhost:3306/my_test" />
                <property name="username" value="root" />
                <property name="password" value="123456" />
            </dataSource>
        </environment>
    </environments>

    <mappers>
        <mapper resource="mapper/StudentMapper.xml"/>
    </mappers>

</configuration>

以下是测试类:

import com.entity.Student;
import com.mapper.IStudentMapper;
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 java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * test
 *
 * @author zhangwugui
 * @since 2018/1/25 15:14
 */
public class MainTest {
    public static void main(String[] args) {
        String resource = "config/mybatis-config.xml";
        InputStream inputStream;
        SqlSession session = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
            // 构建sqlSession工厂
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
            // 获取sqlSession
            session = sqlSessionFactory.openSession();
            // 方法1
            String statement = "com.mapper.IStudentMapper.getAll";
            List<Student> student = session.selectList(statement);
            System.out.println(student);

            // 方法2
            IStudentMapper sessionMapper = session.getMapper(IStudentMapper.class);
            List<Student> list = sessionMapper.getAll();
            System.out.println(list);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            session.close();
        }
    }
}

就这么简单,mybatis就配置完成了,启动main方法我们就可以进行测试了,运行一下,我们看下结果:

[Student{id=1, name='test', age=12}]
[Student{id=1, name='test', age=12}]

我们可以看下,其实配置Mybatis是特别简单的。同样,使用Mybatis进行开发也是很简单的。

下面我们来看mybatis结合spring的使用,并且使用Junit来进行测试,使用log4j来打印日志。

Spring+Mybatis+Druid+Junit

1. 表结构还是Student,我们先看下工程目录

工程目录.png

2. pom文件:spring的包太多,这里为了避免代码太多,没有引入,大家统一引入即可

<dependencies>
<!-- mybatis 配置 -->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>${mybatis.version}</version>
    </dependency>
    <!-- mybatis/spring包 -->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis-spring</artifactId>
        <version>1.3.0</version>
    </dependency>
    <!-- mysql驱动包 -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.30</version>
    </dependency>
    <!-- druid连接池 -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>1.0.20</version>
    </dependency>
    <!-- Mybatis end -->

    <!-- Others -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>
</dependencies>

2. Student实体类不变,而IStudentMapper只需要添加一个注解即可。

@Repository
public interface IStudentMapper {
    List<Student> getAll();
    ...
}

3. IStudentApi.java接口和StudentServiceImpl.java实现类

public interface IStudentApi {
    List<Student> getAll();

    int save(Student article);

    Student update(Student article);

    int delete(int id);

    Student findStudentById(int id);
}
@Service
public class StudentServiceImpl implements IStudentApi{

    @Autowired
    private IStudentMapper iStudentMapper;

    @Override
    public List<Student> getAll() {
        return iStudentMapper.getAll();
    }

    @Override
    public int save(Student student) {
        return iStudentMapper.save(student);
    }

    @Override
    public Student update(Student student) {
        return iStudentMapper.update(student);
    }

    @Override
    public int delete(int id) {
        return iStudentMapper.delete(id);
    }

    @Override
    public Student findStudentById(int id) {
        return iStudentMapper.findStudentById(id);
    }
}

3. StudentMapper.xml不变,mybatis-config.xml如下

<?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>
    <settings>
        <setting name="logImpl" value="LOG4J"/>
    </settings>

    <typeAliases>
        <typeAlias type="com.entity.Student" alias="Student"/>
    </typeAliases>
</configuration>

4. jdbc.properties和log4j.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/my_test?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=TRUE
jdbc.username=root
jdbc.password=123456
### Log4j配置 ###
#定义log4j的输出级别和输出目的地(目的地可以自定义名称,和后面的对应)
#[ level ] , appenderName1 , appenderName2
log4j.rootLogger=DEBUG,console,file

#-----------------------------------#
#1 定义日志输出目的地为控制台
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.Target = System.out
log4j.appender.console.Threshold=DEBUG
####可以灵活地指定日志输出格式,下面一行是指定具体的格式 ###
#%c: 输出日志信息所属的类目,通常就是所在类的全名
#%m: 输出代码中指定的消息,产生的日志具体信息
#%n: 输出一个回车换行符,Windows平台为"/r/n",Unix平台为"/n"输出日志信息换行
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%c]-%m%n

#-----------------------------------#
#2 文件大小到达指定尺寸的时候产生一个新的文件
log4j.appender.file = org.apache.log4j.RollingFileAppender
#日志文件输出目录
log4j.appender.file.File=log/tibet.log
#定义文件最大大小
log4j.appender.file.MaxFileSize=10mb
###输出日志信息###
#最低级别
log4j.appender.file.Threshold=ERROR
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n

#-----------------------------------#
#3 druid
log4j.logger.druid.sql=INFO
log4j.logger.druid.sql.DataSource=info
log4j.logger.druid.sql.Connection=info
log4j.logger.druid.sql.Statement=info
log4j.logger.druid.sql.ResultSet=info

#4 mybatis 显示SQL语句部分
log4j.logger.org.mybatis.example=DEBUG

5. spring-context.xml和spring-db.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/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.0.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:property-placeholder location="classpath:config/*.properties"/>

    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="initialSize" value="10"/>
        <property name="maxActive" value="50"/>
        <property name="maxWait" value="6000"/>
        <property name="minEvictableIdleTimeMillis" value="840000"/>
        <property name="connectionInitSqls" value="set names utf8mb4;"/>
        <property name="validationQueryTimeout" value="2000"/>
        <property name="testWhileIdle" value="true"/>
        <property name="poolPreparedStatements" value="true"/>
        <property name="logAbandoned" value="true"/>
        <property name="proxyFilters">
            <list>
                <ref bean="stat-filter" />
                <ref bean="log-filter" />
            </list>
        </property>
        <property name="filters" value="wall"/>
        <property name="useGlobalDataSourceStat" value="true"/>
        <!--修改mysql的默认隔离级别-->
        <property name="defaultTransactionIsolation" value="2"/>
        <!-- 测试druid功能 end-->
    </bean>

    <bean id="stat-filter" class="com.alibaba.druid.filter.stat.StatFilter">
        <property name="slowSqlMillis" value="10000"/>
        <property name="logSlowSql" value="true"/>
        <property name="mergeSql" value="true"/>
    </bean>
    <bean id="log-filter" class="com.alibaba.druid.filter.logging.Slf4jLogFilter">
        <!--执行sql 显示-->
        <property name="statementExecutableSqlLogEnable" value="true"/>
        <property name="resultSetLogEnabled" value="false"/>
        <property name="dataSourceLogEnabled" value="false"/>
        <property name="connectionLogEnabled" value="false"/>
        <property name="statementLogEnabled" value="false"/>
    </bean>

    <!-- 配置sqlSessionFactory -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="configLocation" value="mybatis/mybatis-config.xml"/>
        <property name="mapperLocations" value="mybatis/StudentMapper.xml"/>
    </bean>

    <!-- 配置mybatis自动扫描Mapper -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
        <property name="basePackage" value="com.mapper"/>
    </bean>

    <!-- 事务管理 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>
    <!-- 使用声明式事务-->
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />

</beans>
<?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:context="http://www.springframework.org/schema/context"
       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-4.0.xsd">

    <context:annotation-config></context:annotation-config>
    <context:component-scan base-package="com"/>
    <import resource="spring-db.xml"/>

</beans>

6. JUnit4ClassRunner.java和MainTest.java

package com.test;

import org.junit.runners.model.InitializationError;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Log4jConfigurer;

import java.io.FileNotFoundException;

/**
 * TODO
 *
 * @author zhangwugui
 * @since 2018/1/24 21:06
 */
public class JUnit4ClassRunner extends SpringJUnit4ClassRunner {
    static {
        try {
            Log4jConfigurer.initLogging("classpath:config/log4j.properties");
        } catch (FileNotFoundException ex) {
            System.err.println("Cannot Initialize log4j");
        }
    }
    public JUnit4ClassRunner(Class<?> clazz) throws InitializationError {
        super(clazz);
    }
}
package com.test;

import com.api.IStudentApi;
import com.entity.Student;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;

import java.util.List;

/**
 * 单元测试
 *
 * @author zhangwugui
 * @since 2018/1/24 18:17
 */
@RunWith(JUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:spring/spring-context.xml"})
public class MainTest  {
    private static final Logger logger = LoggerFactory.getLogger(MainTest.class);

    @Autowired
    private IStudentApi iStudentApi;

    @Test
    public void testGetAll() {
        logger.info("查询全部:=====");
        List<Student> list = iStudentApi.getAll();
        logger.info("结果是:======" + list.toString());
    }
}

运行单元测试,查看运行结果:

[com.test.MainTest]-查询全部:=====
[org.mybatis.spring.SqlSessionUtils]-Creating a new SqlSession
[org.mybatis.spring.SqlSessionUtils]-SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@47406941] was not registered for synchronization because synchronization is not active
[org.springframework.jdbc.datasource.DataSourceUtils]-Fetching JDBC Connection from DataSource
[org.mybatis.spring.transaction.SpringManagedTransaction]-JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@6de6faa6] will not be managed by Spring
[com.mapper.IStudentMapper.getAll]-==>  Preparing: SELECT * FROM Student 
[com.mapper.IStudentMapper.getAll]-==> Parameters: 
[com.mapper.IStudentMapper.getAll]-<==      Total: 1
[com.alibaba.druid.pool.PreparedStatementPool]-{conn-10010, pstmt-20010} enter cache
[org.mybatis.spring.SqlSessionUtils]-Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@47406941]
[org.springframework.jdbc.datasource.DataSourceUtils]-Returning JDBC Connection to DataSource
[com.test.MainTest]-结果是:======[Student{id=1, name='test', age=12}]
[org.springframework.test.context.support.DirtiesContextTestExecutionListener]-After test method: context [DefaultTestContext@4678c730 testClass = MainTest, testInstance = com.test.MainTest@6767c1fc, testMethod = testGetAll@MainTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@29ee9faa testClass = MainTest, locations = '{classpath:spring/spring-context.xml}', classes = '{}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]], class dirties context [false], class mode [null], method dirties context [false].

  到此,我们基于Spring+Mybatis+Druid+Junit的配置正式结束了。通过这些简单的配置,我们可以大致了解spring与Mybatis的运行方式。其中,遇到了一个问题,就是Junit单元测试不打印日志的问题,该问题解决方式参考:
Junit单元测试使用log4j输出日志

下篇文章,我们将开始从源码的角度去分析Mybatis的流程。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,242评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,769评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,484评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,133评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,007评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,080评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,496评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,190评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,464评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,549评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,330评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,205评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,567评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,889评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,160评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,475评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,650评论 2 335

推荐阅读更多精彩内容

  • 1.概述 对于 Java 的开发者来说,在虚拟机的自动内存管理机制的帮助下,不再需要为每一个 new 操作去写配对...
    SawyerZh阅读 3,124评论 3 81
  • 万里无云。天空蓝的很清澈。突然又想去看海,安静的听着海浪拍打的声音,放空一切心思。 九月。阳光照射成片的绿荫。光照...
    罗拉耳朵阅读 323评论 0 1
  • 梧桐花又开了。 去年的五月,也是一个桐花胜放的季节,有一群比我们更为成熟的人开始了他们的冲刺之旅。而今年的五月,同...
    未央之惑阅读 283评论 0 1
  • tf.cast(x, dtype, name=None) 此函数是类型转换函数 参数 x:输入 dtype:转换目...
    MiracleJQ阅读 6,148评论 0 0
  • 清早去上班路上,我纠结了半路要不要把昨晚写的那篇《求什么得什么》上传微博,因为微博确实好久没更新了。我心中的两个小...
    迦颜阅读 649评论 0 0