<%@taglib prefix="" uri=""%>
例如:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
core:核心库
fmt:格式化|国际化
xml:过时了
sql:过时了
函数库:很少使用了
if
forEach
<%--比较大小--%>
3大于4
3不大于4
<%--判断是否登录成功--%>
${name}+欢迎来到主页
您还没有进行登录,请先登录登录
<%--list 集合--%>
<%
ArrayList list = new ArrayList<>();
list.add(new Student("张三",1));
list.add(new Student("李四",2));
list.add(new Student("王五",3));
list.add(new Student("赵六",4));
request.setAttribute("list",list);
%>
${ele.name}------${ele.age}
<%--map 集合--%>
<%
HashMap map = new HashMap<>();
map.put("一个歌手",new Student("邓紫棋",32));
map.put("一个演员",new Student("赵丽颖",35));
map.put("一个锦鲤",new Student("杨超越",25));
request.setAttribute("map",map);
%>
${map.key}
${map.value.name}----${map.value.age}
student.jsp
<student.jsp
student.jsp
<%
String msg=null;
request.setAttribute("msg",msg);
%>
${name}
${smg}
优秀
良好
一般
及格
不及格
<%
String str="在一个页面之内";
pageContext.setAttribute("str","str");
%>
${s}
<%--重定向--%>
百度
符合特定规范的java类
1.导包
2.使用
BeanUtils.populate(user,map);
1.自定义日期的转换格式
DateConverter dc = new DateConverter();
2.设值日期的字符串格式
dc.setPattern(“yyyy-MM-dd”);
3.注册日期的转换器
ConvertUtils.register(dc, Date.class);
BeanUtils.populate(user, map);
本质就是接口,接口可以定义抽象方法
接口的抽象方法=注解的属性
@interface 注解名{}
替代配置文件
对数据进行限定
@Override:加在方法上,该方法是否重写父类的
@FunctionalInterface检查一个接口是不是函数式接口
函数式接口:此接口中只有一个抽象方法
@SupperessWarnings:抑制警告,之需要一个all就可以抑制所有的警告
@Deprecated:标注一个类或者方式过期
是java给我们提供的注解,它的作用就是来限定我们的自定义注解应该加在哪个位置,哪个阶段
规定注解应该保留到哪个位置
@Target
值为ElementType的枚举值
TYPE:作用在类 接口 等上面
METHOD:作用方法上面 @Target(ElementType.METHOD)
FIELD:作用字段上面
规定注解应该保留到哪个阶段
@Retention
值为RetentionPolicy的三个枚举值
SOURCE:只在代码中保留,在字节码文件中就删除了
CLASS:在代码和字节码文件中保留
RUNTIME:所有阶段都保留@Retention(RetentionPolicy.RUNTIME)
例子
注解的属性:
}
基本类型:四类八种,byte short int long char booolean float double
字符串类型:String
枚举类型
注释类型
字节码class类型型
数组类型
//定义数据库所需要的四参数
@Targent(ElementType.METHOD)//加在方法上
@Retention(RetentionPolicy.RUNTIME)//保留在运行阶段
public @interface JDBCAnnotation {
String driverClass() default "com.mysql.jdbc.Driver";
String url() default "jdbc:mysql://localhost:3306/hbm";
String user() default "root";
String password() default "123456";
}
@JDBCAnnotation(password = "123456")
public static Connection getConnection() throws NoSuchMethodException, ClassNotFoundException, SQLException {
//获取该类的字节码文件对象
Class clazz= JDBCUtils.class;
//获取方法的对象
Method m = clazz.getMethod("getConnection");
//判断该方法上是否有注解有的话就进行判断
boolean b = m.isAnnotationPresent(JDBCAnnotation.class)
if(b){//如果方法上面有注解就获取注解而且拿到注解的属性值
JDBCAnnotation annotation = m.getAnnotation(JDBCAnnotation.class);
//获取注解属性的值
String driverClass = annotation.driverClass();
String url = annotation.url();
String user = annotation.user();
String password = annotation.password();
Class.forName(driverClass);
return DriverManager.getConnection(url,user,password);
}
return null;
}
}