学习主题:SpringBoot
学习目标:
对应视频:
http://www.itbaizhan.cn/course/id/85.html
对应文档:
无
对应作业
1. Thymeleaf语法详解-字符串操作
(1) th:text的作用是什么?
在页面中输出值
(2) th:value的作用是什么?
可以将一个值放入input标签的value中
(3) 什么是Thymeleaf的内置对象?
(4) 内置对象的语法是什么?
1. 调用内置对象一定要用#
2. 大部分的内置对象都以s结尾
2. Thymeleaf语法详解-日期转换操作
(1) 在Thymeleaf中使用哪个内置对象转换日期?
Dates
(2) 常见的处理日期函数有哪些?
日期处理
${#dates.format(key)} 格式化日期 默认的以浏览器默认语言为格式化标准
${#dates.format(key,’yyyy/MM/dd’)} 按照自定义的格式做日期转换
${#dates.year(key)} 取年
${#dates.month(key)} 取月
${#date.day(key)} 取日
3. Thymeleaf语法详解-条件判断
(1) th:if的作用是什么?
条件判断语句
th:if :if判断
<span th:if=”${sex} == ‘男’”>
性别: 男
</span>
<span th:if=”${sex} == ‘女’”>
性别:女
</span>
(2) th:switch的作用是什么?
相当于java中的switch
Th:swith : swith 判断
<div th:swith=”${id}”>
<span th:case=”1”>ID 为1</span>
<span th:case=”2”>ID 为2</span>
</div>
4. Thymeleaf语法详解-迭代遍历
(1) th:each的作用是什么?
遍历,相当于 foreach
(2) th:each中可以获取哪些状态变量?
Th:each 也是一个状态变量
分享/讲解/扩展思考
点名提问从第一节课到最后一节课分别学到了什么,直到同学们把所有的知识点都说出来并且保证无误。
第218次(SpringBoot)
学习主题:SpringBoot
学习目标:
对应视频:
http://www.itbaizhan.cn/course/id/85.html
对应文档:
无
对应作业
5. Thymeleaf语法详解-获取作用域对象中的数据
(1) 在Thymeleaf中如何获取HttpServletRequest对象中的值?
(2) 在Thymeleaf中如何获取HttpSession中的值?
(3) 在Thymeleaf中如何获取ServletContext中的值?
6. Thymeleaf语法详解-URL表达式
(1) URL表达式的语法是什么?
@{url表达式}
(2) 在URL表达式中可以给定几种URL格式?
相对路径和绝对路径
绝对路径
相对路径:相当于当前项目的根
(3) 如何在URL表达式中传递参数?
(4) 如何在URL表达式中通过RESTful风格传递参数?
或者
7. Spring Boot整合MyBatis-创建项目
(1) Spring MVC+Spring Boot+MyBatis整合需要添加哪些坐标?
<!-- SpringBoot启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Thymeleaf启动器 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- Mybatis启动器 -->
<!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<!-- mysql驱动 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--数据源 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.10</version>
</dependency>
(2) Spring Boot整合MyBatis时如何在全局配置文件中配置数据源?
(3) Spring Boot整合MyBatis时如何在全局配置文件中配置数据库连接池?
(4) Spring Boot整合MyBatis时如何在全局配置文件中配置MyBatis的包别名?
8. SpringBoot整合MyBatis完成添加用户
(1) @MapperScan(" ")注解的作用是什么?
用户扫描MyBatis的mapper接口
指定要变成实现类的接口所在的包,然后包下面的所有接口在编译之后都会生成相应的实现类
添加@MapperScan(“com.winter.dao”)注解以后,com.winter.dao包下面的接口类,在编译之后都会生成相应的实现类
9. SpringBoot整合MyBatis完成用户查询
(1) 在项目中编写一个查询所有用户的案例
UserController
@RequestMapping("/user/select")
public String usercontroller(Model model) {
List<Users> userList= userService.selectUser();
model.addAttribute("userList", userList);
return "showUser";
}
UserServiceImpl
@Override
public Users selectById(Integer userid) {
return userMapping.selectById(userid);
};
UserMapping.xml
<select id="selectAll" resultType="users">
select * from users
</select>
ShowUser.html
<body>
<table border="1px " >
<tr th:each="user : ${userList}">
<td th:text="${user.userid}"></td>
<td th:text="${user.username}"></td>
<td th:text="${user.userage}"></td>
<td><a th:href="@{/user/selectByid(userid=${user.userid})}">更新数据</a></td>
<td><a th:href="@{/user/delete(userid=${user.userid})}">删除数据</a></td>
</tr>
</table>
</body>
10. SpringBoot整合MyBatis完成用户修改-数据回显
(1) 在项目中编写一个预更新查询用户的案例。
11. SpringBoot整合MyBatis完成用户修改-更新用户
(1) 在项目中编写一个更新用户的案例。
数据回显和数据更新
UserController
//数据回显
@RequestMapping("/user/selectByid")
public String usercontroller2(Model model,Integer userid) {
Users users = userService.selectById(userid);
model.addAttribute("user", users);
return "update";
}
//数据更新
@RequestMapping("/user/update")
public String usercontroller3(Users users) {
userService.updateUser(users);
return "ok";
}
UserServiceImpl
@Override
public Users selectById(Integer userid) {
return userMapping.selectById(userid);
};
public void updateUser(Users users) {
userMapping.updateUser(users);
}
UserMapping.xml
<select id="selectById" resultType="users">
select * from users where userid=#{userid}
</select>
<select id="updateUser" parameterType="users" >
update users set username=#{username} ,userage=#{userage} where userid=#{userid}
</select>
Update.html
<body>
<form th:action="@{/user/update}" method="post">
<input type="hidden" name="userid" th:value="${user.userid}" />
用户名:<input type="text" name="username" th:value="${user.username}" />
年龄 <input type="text" name="userage" th:value="${user.userage}"/>
<input type="submit" value="修改提交数据">
</form>
</body>
ok.html
<body>
更新成功
</body>
12. SpringBoot整合MyBatis完成用户删除
(1) 在项目中编写一个删除用户的案例。
UserController
@RequestMapping("/user/delete")
public String usercontrole(Integer userid) {
userService.deleteById(userid);
return "ok";
}
UserServiceImpl
public void deleteById(Integer userid) {
userMapping.deleteById(userid);
}
UserMapping.xml
<delete id="deleteById">
delete from users where userid=#{userid}
</delete>
showUser.html
分享/讲解/扩展思考
点名提问从第一节课到最后一节课分别学到了什么,直到同学们把所有的知识点都说出来并且保证无误。