• 业务字段设计

• 数据库创建
• CRUD操作
• MyBatis集成
• 注解和XML定义
• ViewObject和DateTool
• 首页开发
 
 
• 业务字段设计
实体:

name:logub_ticket
lable:
id
user_id
ticket
expired
status
• 数据库创建
GUI版本管理工具创建,然后通过GUI转SQL;
• CRUD操作
 
insert into table_name (列1, 列2,...) VALUES (值1, 值2,....);
select 列名1,列名2 from 表名称 where 条件;
条件: between 1 and 2 order by 3 desc
UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
 
• MyBatis集成
1. application.properties增加spring配置数据库链接地址
spring.datasource.username=root
spring.datasource.password=qwertyuiop
mybatis.config-location=classpath:mybatis-config.xml
同时:在配置的同级别目录下:resources/templates建立粘贴建立官网有:mybatis-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
<configuration>
 
<settings>
<!-- Globally enables or disables any caches configured in any mapper under this configuration -->
<setting name="cacheEnabled" value="true"/>
<!-- Sets the number of seconds the driver will wait for a response from the database -->
<setting name="defaultStatementTimeout" value="3000"/>
<!-- Enables automatic mapping from classic database column names A_COLUMN to camel case classic Java property names aColumn -->
<setting name="mapUnderscoreToCamelCase" value="true"/>
<!-- Allows JDBC support for generated keys. A compatible driver is required.
This setting forces generated keys to be used if set to true,
as some drivers deny compatibility but still work -->
<setting name="useGeneratedKeys" value="true"/>
</settings>
 
<!-- Continue going here -->
 
</configuration>
2. pom.xml引入mybatis-spring-boot-starter和mysql-connector-java
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>1.1.1</version>
</dependency>
 
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
 
 
 
DAO层建立modul相关的userDao来通过mybatis访问数据库库:
//注解配置;
@Mapper
public interface UserDAO {
String TABLE_NAME = "user";
String INSET_FIELDS = " name, password, salt, head_url ";
String SELECT_FIELDS = " id, name, password, salt, head_url";
//通过抽象,实现crud的复用;
@Insert({"insert into ", TABLE_NAME, "(", INSET_FIELDS,
") values (#{name},#{password},#{salt},#{headUrl})"})
int addUser(User user);
 
@Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where id=#{id}"})
User selectById(int id);
 
@Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, " where name=#{name}"})
User selectByName(String name);
 
@Update({"update ", TABLE_NAME, " set password=#{password} where id=#{id}"})
void updatePassword(User user);
 
@Delete({"delete from ", TABLE_NAME, " where id=#{id}"})
void deleteById(int id);
}

//xml配置,在相应的resources下建立DAO相应目录的的xml;

<mapper namespace="com.nowcoder.dao.QuestionDAO"> <sql id="table">question</sql> <sql id="selectFields">id,title, content,comment_count,created_date,user_id </sql> <select id="selectByUserIdAndOffset" resultType="com.nowcoder.model.Question"> SELECT <include refid="selectFields"/> FROM <include refid="table"/>
<if test="userId != 0"> WHERE user_id = #{userId} </if> ORDER BY id DESC LIMIT #{offset},#{limit} </select> </mapper>
 
 
• 注解和XML定义
• ViewObject和DateTool
• 首页开发

数据库CRUD操作以及MyBatis的配置使用的更多相关文章

  1. 【转】数据库CRUD操作

    数据库CRUD操作 一.删除表   drop table 表名称 二.修改表 alter   table 表名称 add  列名 数据类型   (add表示添加一列) alter  table  表名 ...

  2. Mybatis基于代理Dao实现CRUD操作 及 Mybatis的参数深入

    Mybatis基于代理Dao实现CRUD操作 使用要求: 1.持久层接口和持久层接口的映射配置必须在相同的包下 2.持久层映射配置中mapper标签的namespace属性取值必须是持久层接口的全限定 ...

  3. 05 Mybatis的CRUD操作和Mybatis连接池

    1.CRUD的含义 CRUD是指在做计算处理时的增加(Create).读取(Retrieve)(重新得到数据).更新(Update)和删除(Delete)几个单词的首字母简写.主要被用在描述软件系统中 ...

  4. 10月16日下午MySQL数据库CRUD操作(增加、删除、修改、查询)

    1.MySQL注释语法--,# 2.2.后缀是.sql的文件是数据库查询文件. 3.保存查询. 关闭查询时会弹出提示是否保存,保存的是这段文字,不是表格(只要是执行成功了表格已经建立了).保存以后下次 ...

  5. 数据库CRUD操作:C:create创建(添加)、R:read读取、U:update:修改、D:delete删除;高级查询

    1.注释语法:--,#2.后缀是.sql的文件是数据库查询文件3.保存查询4.在数据库里面 列有个名字叫字段   行有个名字叫记录5.一条数据即为表的一行 CRUD操作:create 创建(添加)re ...

  6. 数据库CRUD操作

    CRUD操作: C:create 增加数据: insert into 表名 values('N001','汉族') 普通 insert into 表名 values('','','') 如果有自增长列 ...

  7. django notes 六:数据库 CRUD 操作

    CRUD 也没什么可说的,django 提供了完善的 orm  api, 直接用就行了. 我只贴几个列子,一看就明白了,自己再用用就熟了. # create b = Blog(name='Beatle ...

  8. 使用node_redis进行redis数据库crud操作

    正在学习使用pomelo开发游戏服务器,碰到node.js操作redis,记录一下 假设应用场景是操作一个用户表的数据 引入node_redis库,创建客户端 var redis = require( ...

  9. 【Mybatis】MyBatis对表执行CRUD操作(三)

    本例在[Mybatis]MyBatis配置文件的使用(二)基础上继续学习对表执行CRUD操作 使用MyBatis对表执行CRUD操作 1.定义sql映射xml文件(EmployeeMapper.xml ...

随机推荐

  1. Win10U盘启动盘制作及Win10系统安装

    准备工具: 1:一个8GU盘 2:下载MediaCreationTool1803.exe程序 及参考文档. 启动盘制作步骤: 1:运行 2:按照截图步骤依次...... 3:制作完成后插拔一下U盘在看 ...

  2. [Swift]LeetCode331. 验证二叉树的前序序列化 | Verify Preorder Serialization of a Binary Tree

    One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, ...

  3. [Swift]LeetCode701. 二叉搜索树中的插入操作 | Insert into a Binary Search Tree

    Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert t ...

  4. [Swift]LeetCode720. 词典中最长的单词 | Longest Word in Dictionary

    Given a list of strings words representing an English Dictionary, find the longest word in words tha ...

  5. 使用jQuery获取元素的宽度或高度的几种情况

    今天说说使用jQuery获取元素大小的遇到几种情况 使用jQuery获取元素的宽度或高度的有几种情况: 1.使用width(),它只能获取当前元素的内容的宽度: 2.使用innerWidth(),它只 ...

  6. windows下golang实现Kfaka消息发送及kafka环境搭建

    kafka环境搭建: 一.安装配置java-jdk (1)kafka需要java环境,安装java-jdk,下载地址:https://www.oracle.com/technetwork/java/j ...

  7. 【git】idea /git bash命令 操作分支

    1.需求 因为目前要对项目做一些改动,而项目又即将上线,这些新的改动又不需要一起上线,所以这个时候需要在原有的master分支上重新拉出一个分支进行开发. 2.分支操作 打开git bash工具→切换 ...

  8. Vue生命周期详解

    Vue所有的生命周期钩子自动绑定在this上下文到实例中,因此你可以访问数据,对属性和方法进行运算.这意味着你不能使用箭头函数来定义一个生命周期方法.这是因为箭头函数绑定了父上下文,因此this与你期 ...

  9. APK安装成功后点击"打开",按Home键,在桌面点击图标后应用重启

    转载:http://blog.csdn.net/kepoon/article/details/7468688 问题: 安装系统SD卡里面的apk或者原有的程序更新版本的时候,会遇到升级安装成功之后的一 ...

  10. EF架构~TransactionScope与SaveChanges的关系

    回到目录 TransactionScope是.net环境下的事务,可以提升为分布式事务,这些知识早在很久前就已经说过了,今天不再说它,今天主要谈谈Savechanges()这个方法在Transacti ...