• 业务字段设计

• 数据库创建
• 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. 记录一次JavaWeb开发的乱码解决

    POST提交的中文,测试能正确接收到,而且在控制台打印出中文 但是存到数据库乱码 查看了数据库,设置的是utf-8,最后发现应该在数据库连接的地方设置: jdbc:mysql://localhost: ...

  2. mysql_study_2

    select 代码: CREATE DATABASE mysql_shiyan; use mysql_shiyan; CREATE TABLE department ( dpt_name ) NOT ...

  3. 课程五(Sequence Models),第三周(Sequence models & Attention mechanism) —— 2.Programming assignments:Trigger word detection

    Expected OutputTrigger Word Detection Welcome to the final programming assignment of this specializa ...

  4. 4.DOM

    定义 文档对象模型(Document Object Model)是一种用于HTML和XML文档的编程接口. 查找元素 1.直接查找 document.getElementById 根据ID获取一个标签 ...

  5. java基础(十一 )-----反射——Java高级开发必须懂的

    本文我们通过一个实际的例子来演示反射在编程中的应用,可能之前大家对反射的学习,仅仅是停留在概念层面,不知道反射究竟应用在哪,所以是一头雾水.相信通过这篇教程,会让你对反射有一个更深层次的认知. 概念 ...

  6. Android--从系统Gallery获取图片

    前言 在Android应用中,经常有场景会需要使用到设备上存储的图片,而直接从路径中获取无疑是非常不便利的.所以一般推荐调用系统的Gallery应用,选择图片,然后使用它.本篇博客将讲解如何在Andr ...

  7. 知其所以然~redis的原子性

    原子性 原子性是数据库的事务中的特性.在数据库事务的情景下,原子性指的是:一个事务(transaction)中的所有操作,要么全部完成,要么全部不完成,不会结束在中间某个环节. 对于Redis而言,命 ...

  8. Chapter 4 Invitations——14

    "Hi, Bella." “你好,Bella” "What's up?" I said as I was unlocking the door. “怎么了?” ...

  9. Jenkins自定义主题

    x下载自定义样式 http://afonsof.com/jenkins-material-theme/ 打开连接 最后点击:DOWNLOAD TOUR THEME! 得到样式文件:jenkins-ma ...

  10. RabbitMQ消息队列(十一)-如何实现高可用

    在前面讲到了RabbitMQ高可用集群的搭建,但是我们知道只是集群的高可用并不能保证应用在使用消息队列时完全没有问题,例如如果应用连接的RabbitMQ集群突然宕机了,虽然这个集群时可以使用的,但是应 ...