MyBatis 模板
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>
<!-- property from external resources -->
<properties resource="config/applications.properties"/>
<!-- settings -->
<settings>
<setting name="cacheEnabled" value="true"/>
<setting name="logImpl" value="STDOUT_LOGGING"/>
<!--
<setting name="lazyLoadingEnabled" value="true" />
<setting name="multipleResultSetsEnabled" value="true" />
<setting name="useColumnLabel" value="true" />
<setting name="useGeneratedKeys" value="false" />
<setting name="autoMappingBehavior" value="PARTIAL" />
<setting name="defaultExecutorType" value="SIMPLE" />
<setting name="defaultStatementTimeout" value="25000" />
<setting name="safeRowBoundsEnabled" value="false" />
<setting name="mapUnderscoreToCamelCase" value="false" />
<setting name="localCacheScope" value="SESSION" />
<setting name="jdbcTypeForNull" value="OTHER" />
<setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode ,toString" />
-->
</settings>
<!-- type aliases(full class name -> simple class name) -->
<typeAliases>
<!--
<typeAlias alias="Student" type="com.mybatis3.domain.Student" />
-->
<package name="per.piers.onlineJudge.model"/>
</typeAliases>
<!-- type handlers -->
<typeHandlers>
<typeHandler handler="per.piers.onlineJudge.handler.SexTypeHandler" javaType="per.piers.onlineJudge.model.Sex" jdbcType="BOOLEAN"/>
</typeHandlers>
<!-- environment -->
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</dataSource>
</environment>
<environment id="production">
<transactionManager type="MANAGED"/>
<dataSource type="JNDI">
<property name="data_source" value="java:comp/jdbc/mybatis"/>
</dataSource>
</environment>
</environments>
<!-- mappers location -->
<mappers>
<!--
<mapper url="file:///D:/mybatisdemo/app/mappers/TutorMapper.xml" />
<mapper class="com.mybatis3.mappers.TutorMapper" />
-->
<mapper resource="mapper/UserMapper.xml"/>
</mappers>
</configuration>
applications.properties:
jdbc.driverClassName=com.mysql.cj.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/online_judge?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8&useSSL=true
jdbc.username=root
jdbc.password=woaimysql-135
context.xml(JNDI配置数据源):
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="mybatis"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/onlineJudge"
username="root"
password="woaimysql-135"
maxTotal="20"
maxIdle="10"
maxWaitMillis="10000" />
</Context>
UserMapper.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="per.piers.onlineJudge.mapper.UserMapper">
<insert id="insertUser" parameterType="User" useGeneratedKeys="true" keyProperty="id">
INSERT INTO online_judge.users (email, password, name, sex, role, enabled)
VALUES (#{email}, #{password}, #{name}, #{sex}, #{role}, #{enabled})
</insert>
<update id="updateUser" parameterType="User">
UPDATE online_judge.users
SET email = #{email}, password = #{password}, name = #{name}, sex = #{sex}, role = #{role}, enabled = #{enabled}
WHERE id = #{id}
</update>
<delete id="deleteUser" parameterType="int">
DELETE FROM online_judge.users
WHERE id = #{id}
</delete>
<select id="selectUserByEmail" parameterType="String" resultMap="userResult">
SELECT *
FROM online_judge.users
WHERE email = #{email}
</select>
<resultMap id="userResult" type="User">
<id column="id" property="id"/>
<result column="email" property="email"/>
<result column="password" property="password"/>
<result column="name" property="name"/>
<result column="sex" property="sex"/>
<result column="enabled" property="enabled"/>
<result column="role" property="role"/>
</resultMap>
</mapper>
MyBatis 模板的更多相关文章
- mybatis模板
因为这里是说mybatis的,所以呢 servlet就不做多说了,代码也不在这里贴出来了. log4j.properties log4j.rootLogger=DEBUG,Console log4j. ...
- Spring mybatis源码篇章-MybatisDAO文件解析(一)
前言:通过阅读源码对实现机制进行了解有利于陶冶情操,承接前文Spring mybatis源码篇章-SqlSessionFactory 加载指定的mybatis主文件 Mybatis模板文件,其中的属性 ...
- springboot mybatis 多数据源配置
首先导入mybatis等包,这里就不多说. 下面是配置多数据源和mybatis,每个数据源对应一套mybatis模板 数据源1: package com.aaaaaaa.config.datasour ...
- SpringBoot+SpringCloud+vue+Element开发项目——集成MyBatis框架
添加mybatis-spring-boot-starter依赖 pox.xml <!--mybatis--> <dependency> <groupId>org.m ...
- Spring mybatis源码篇章-Mybatis主文件加载
通过阅读源码对实现机制进行了解有利于陶冶情操,承接前文Spring mybatis源码篇章-SqlSessionFactory 前话 本文承接前文的内容继续往下扩展,通过Spring与Mybatis的 ...
- Mybatis总结一之Mybatis项目的创建
一.mybatis概念 Mybatis是对象和表之间映射关系的持久层框架. 二.Mybatis的导入与创建 第一步,创建web项目,引入mybatis依赖的jar包----mybatis-3.4.6. ...
- Thymeleaf+SpringBoot+Mybatis实现的齐贤易游网旅游信息管理系统
项目简介 项目来源于:https://github.com/liuyongfei-1998/root 本系统是基于Thymeleaf+SpringBoot+Mybatis.是非常标准的SSM三大框架( ...
- spring boot集成mybatis框架
概述 中文官网:http://www.mybatis.cn 参考教程:https://www.w3cschool.cn/mybatis MyBatis Plus:http://mp.baomidou. ...
- Spring从认识到细化了解
目录 Spring的介绍 基本运行环境搭建 IoC 介绍: 示例使用: 使用说明: 使用注意: Bean的实例化方式 Bean的作用范围的配置: 补充: DI: 属性注入: 补充: IoC的注解方式: ...
随机推荐
- Linux基本命令(二)
1. 输出重定向命令:> Linux允许将命令执行结果重定向到一个文件,本应显示在终端上的内容保存到指定文件中. 如:ls > test.txt ( test.txt 如果不存在,则创建, ...
- com.octo.captcha.service.CaptchaServiceException: Invalid ID, could not validate unexisting o
<p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px;"& ...
- [Angular Directive] Combine HostBinding with Services in Angular 2 Directives
You can change behaviors of element and @Component properties based on services using @HostBinding i ...
- <Linux> xm 命令
xm console <域ID> ctrl+ ] 退出虚拟机到宿主 xm reboot <域ID> xm pause <域I ...
- php中的foreach如何使用?
php中的foreach如何使用? 一.总结 1.foreach (array_expression as $value) 2.foreach (array_expression as $key =& ...
- nopCommerce 3.9 接口笔记
接口笔记 Nop.Services.Configuration ISettingService : 配置接口(查看) Nop.Services.Localization ILocalizationSe ...
- xCode中怎样保存自己的代码块
在开发iOS的过程中.xCode肯定是用得最多的工具.没有之中的一个.由于苹果官方提供的就这一个平台,尽管没有竞争对手,但秉承苹果一贯的注重细节的原则,xCode还是一款相当不错的IDE. 作为一名i ...
- Android中再按一次退出实现
很多应用中都有一个在用户后退的时候显示"再按一次退出"的提醒,这个怎么实现呢?有两种方式 第一种方式(最常用) long waitTime = 2000; long touchTi ...
- leveldb学习:skiplist
leveldb中的memtable仅仅是一个封装类,它的底层实现是一个跳表. 跳表是一种基于随机数的平衡数据结构.其它的平衡数据结构还有红黑树.AVL树.但跳表的原理比它们简单非常多.跳表有点像链表, ...
- Linux初接触随笔02
刚开始把Linux既拿来用,又拿来学习怎么用,感觉真不顺手,手上应该有一本实体书籍,专门拿来学习用会好点,但是我现在手头没有,又把系统作为日常使用,只能说太不友好了,坚持不住了,以后等需要用的时候再弄 ...