JavaWeb
SpringBoot
IOC(Inversion Of Control),控制反转。
DI(Dependecy Injection),依赖注入。@Autowired
Bean对象,为容器IOC创建的对象。
Bean的声明:@Component,@Controller——Controller层,@Service——services层,@Repository——DAO层
//当出现上述注解,会自动创建Bean对象。
依赖注入冲突问题
如果遇到多个Bean容器无法自动注解,使用
1 2
| @Autowired @Qualifier("Bean名称")
|
或使用注解
1
| @Resource(name = "Bean名称")
|
使用
依赖注入常见方法
1 2 3 4
| @Autowired private EmployeeMapper employeeMapper;
|
数据库(Database)
MySQL数据模型
二维表。属于关系型数据库。
连接远程服务器数据库
1
| mysql -hIP地址 -P端口 -u用户名 -p密码
|
SQL分类
DDL(Data Definition Language)数据定义语言,定义数据对象(数据库、表、字段)
DML(Data Manipulation Language) 数据操作语言,如增删改
DQL(Data Query Language)数据查询语言
DCL(Data Control Language)数据控制语言,如增添用户、设置权限
DDL语法
数据库操作
添加数据库
1
| create databse if no exists 数据库名;
|
删除数据库
1
| drop database if not exists 数据库名;
|
查询当前数据库
使用数据库
表结构操作
表操作

1 2 3 4 5 6 7 8
| //创建表 create table employee( id int comment 'ID,唯一标识', username varchar(20) comment '用户名', password varchar(20) comment '用户名' ) comment '用户表'; //修改表名 rename table tb_emp to emp;
|
表约束
非空约束 not null
唯一约束 unique
主键约束 primary key
默认约束 default
1 2 3 4 5
| create table employee( id int primary key comment 'ID,唯一标识', username varchar(20) not null unique comment '用户名', password varchar(20) not null comment'用户名' ) comment '用户表';
|
字段操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| //添加字段 alter table tb_emp add qq varchar(11) comment 'QQ'; //改变字段类型 alter table tb_emp modify qq varchar(13) comment 'QQ'; //改变字段名称 alter table tb_emp change qq qq_num varchar(13) comment 'QQ'; //删除字段 alter table tb_emp drop column qq_num;
//增加数据 insert into tb_emp (name,female) values ('qq',1); //更新数据 update tb_emp set name = 'QQ' where id = 1; //删除数据 delete from tb_emp where name = 'qq';
|
参数占位符

Mybatis
自动映射
Java命名,遵循小驼峰命名:例如,mySql, myName
数据库SQL命名,遵循下划线命名:例如,my_sql, my_name
使用自动映射

动态SQL
常见标签
where标签
1 2
| <where> <if test="name != NULL"> and name = #{name} </if></where>
|
set标签
1 2
| <set><if test="name != NULL"> name = #{name},</if></set>
|
foreach标签
1 2 3 4 5
| <foreach collection="ids" item="id" separator="," open="(" close=")" > #{id} </foreach>
|
sql、include标签
1 2 3 4 5 6
| <sql id ="commentSelect"> select id, name, gender from <sql>
<include refid="commentSelect"><>
|
工程学习
pojo
封装实体类的时候,封装数据库int类型时,要用封装类integer
因为数据库表中可能出现NULL值,integer类型能出现NULL值对应
工程注解类
路径注解:@Pathvariable
封装json类:@RequestBody
设置默认值:@RequestParam(defaultValue=”1”)
PageHelper分页查询
1 2 3 4 5
| PageHelper.startPage(employeePageQueryDTO.getPage(), employeePageQueryDTO.getPageSize()); Page<Employee> page = employeeMapper.pageQuery(employeePageQueryDTO); long total = page.getTotal(); List<Employee> records = page.getResult(); return new PageResult(total, records);
|
前端上传
MultipartFile
UUID(通用唯一识别码)

传输大小限制multipart