week 4.6-4.12
- | Study-update |
---|---|
-Mon | el表达式,jstl |
-Tue | jstl标签,JSON |
-Wes | Mybatis |
-Thu | Study-update |
-Fri | Study-update |
-Sat | 二叉树,mybatis配置 |
-Sun | myBatis环境配置 |
4.06 Monday
<%@ page import="com.demogorgon.model.User" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %><%--
Created by IntelliJ IDEA.
User: lzr
Date: 2020/4/5
Time: 4:17 下午
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
request.setAttribute("number",2000);
User user=new User("mike","123",12,"男",false);
request.setAttribute("user",user);
session.setAttribute("user","lzr");
application.setAttribute("connection","true");
Map<String,String> map=new HashMap<String,String>();
map.put("name1","123");
request.setAttribute("map",map);
List<User> userList=new ArrayList<User>();
userList.add(new User("mike","123",12,"男",false));
userList.add(new User("mike","123",12,"男",false));
userList.add(new User("mike","123",12,"男",false));
userList.add(new User("mike","123",12,"男",false));
request.setAttribute("userList",userList);
%>
在线人数为:${requestScope.number}
当前用户:${sessionScope.user}
连接状态:${applicationScope.connection}
用户名为:${user.username}
Map取数据:${requestScope.map.name1}
List取数据:${userList[2].username}
取当前项目名:${pageContext.request.contextPath}
</body>
</html>
jstl
引入jar包,在jsp引入标签库,
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
4.07 Tueday
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.demogorgen.model.User" %>
<%@ page import="java.util.List" %><%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2020/4/7
Time: 11:12
To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<c:set var="age" value="1" scope="request"></c:set>
判断标签
<c:if test="${age>3}">
大于三
</c:if>
分支标签
<c:choose>
<c:when test="${age>3}">年龄大于三</c:when>
<c:otherwise>年龄小于三</c:otherwise>
</c:choose>
循环标签
<c:forEach var="i" begin="0" end="9">
用$取得i
${i}
</c:forEach>
<%
List<User> userList=new ArrayList<User>();
userList.add(new User("1","123",12,"男",false));
userList.add(new User("1","123",12,"男",false));
userList.add(new User("1","123",12,"男",false));
userList.add(new User("1","123",12,"男",false));
request.setAttribute("user",userList);
%>
循环取得元素
<c:forEach items="${user}" var="u">
${u.username}<br/>
</c:forEach>
</body>
</html>
JSON
/**
* @author lzr
* @date 2020 07 22:48
* @description
*/
public class jsonTest {
public static void main(String[] args) {
//序列化 持久化
Goods goods=new Goods("1","2","3");
String json=JSON.toJSONString(goods);
System.out.println(json);
//反序列化 json解析
String s="{\"description\":\"2\",\"name\":\"1\",\"price\":\"3\"}";
Goods goods1=JSON.parseObject(s,Goods.class);
System.out.println(goods1.getName());
System.out.println(goods1.getDescription());
System.out.println(goods1.getPrice());
}
}
4.09 Thuesday
Mybatis是一个轻量级的简化数据库操作的框架。
4.11 Saturday
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<!-- 使用JDBC的事务-->
<transactionManager type="JDBC"/>
<!-- 使用连接池连接数据库-->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/ssm_mybatis"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mapper/UserMapper.xml"/>
</mappers>
</configuration>