• 业务字段设计

• 数据库创建
• 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. You need to use a Theme.AppCompat theme (or descendant) with this activity 问题解决

    You need to use a Theme.AppCompat theme (or descendant) with this activity 问题解决 问题代码 void initCommit ...

  2. [Swift]LeetCode22. 括号生成 | Generate Parentheses

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  3. [Swift]LeetCode41. 缺失的第一个正数 | First Missing Positive

    Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2, ...

  4. [Swift]LeetCode326. 3的幂 | Power of Three

    Given an integer, write a function to determine if it is a power of three. Example 1: Input: 27 Outp ...

  5. 开启SSH

    开启 ssh 远程连接 1.修改 sshd_config 输入 sudo vim /etc/ssh/sshd_config 做如下修改 PermitRootLogin yes [需要把注释 #号去掉, ...

  6. [Abp 源码分析]二、模块系统

    0.简介 整个 Abp 框架由各个模块组成,基本上可以看做一个程序集一个模块,不排除一个程序集有多个模块的可能性.可以看看他官方的这些扩展库: 可以看到每个项目文件下面都会有一个 xxxModule ...

  7. Java核心技术及面试指南的视频讲解和代码下载位置

    都是百度云盘,均无密码 代码下载位置: https://pan.baidu.com/s/1I44ob0vygMxvmj2BoNioAQ 视频讲解位置: https://pan.baidu.com/s/ ...

  8. Java核心技术及面试指南 多线程部分的基本面试题总结以及答案

    7.1.5 (1) 如果某个类已经继承(extends)了一个类,那么让这个类具有多线程的特性? implements runnable类或通过线程池 7.1.5  (2)启动一个线程是用run()还 ...

  9. Quartz.NET学习笔记(二) Job和JobDetails

    Job和JobDetails的关系 接一篇的例子 ISchedulerFactory schedFact = new StdSchedulerFactory(); IScheduler sched = ...

  10. Android中广播接收者BroadcastReceiver详解

    1. 接收系统的广播步骤 (1)  新建一个类继承BroadcastReceiver 以监听sd卡状态的广播接收者为例 public class SdCardBroadcastReceiver ext ...