尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

01-框架--Maven

01-框架--Maven 1.为什么要学习框架框架称之为软件半成品不包含具体的业务提高代码的开发效率2.Maven的作用1.项目构建项目的编译、部署、测试、运行、调试等等软件开发流程等可以参与2.依赖管理第三方jar传统方式弊端1、jar包过于分散需要程序员手动查找2、jar包之间会有依赖关系版本容易出错3. Maven仓库存放jar的位置4. MavenSe工程目录5. Maven导入jar包一般的导入jar包dependencies dependency groupIdjunit/groupId artifactIdjunit/artifactId version4.12/version /dependency dependency groupIdmysql/groupId artifactIdmysql-connector-java/artifactId version8.0.28/version /dependency /dependencies父工程导入jar包groupIdorg.example/groupId artifactIdfather/artifactId version1.0-SNAPSHOT/version packagingpom/packaging modules moduleson/module /modules properties maven.compiler.source17/maven.compiler.source maven.compiler.target17/maven.compiler.target project.build.sourceEncodingUTF-8/project.build.sourceEncoding !-- 此处定义junit的版本 junit-version junit.junit.version -- junit-version4.12/junit-version /properties dependencyManagement dependencies dependency groupIdjunit/groupId artifactIdjunit/artifactId version4.12/version /dependency /dependencies /dependencyManagement子工程链接父工程jar包parent groupIdorg.example/groupId artifactIdfather/artifactId version1.0-SNAPSHOT/version /parent artifactIdson/artifactId properties maven.compiler.source17/maven.compiler.source maven.compiler.target17/maven.compiler.target project.build.sourceEncodingUTF-8/project.build.sourceEncoding !-- 此处定义junit的版本 junit-version junit.junit.version -- junit-version4.12/junit-version /properties dependencies dependency groupIdjunit/groupId artifactIdjunit/artifactId version${junit-version}/version scopetest/scope /dependency /dependencies6. Maven继承父工程起到jar包版本管理的作用并且jar的类型是pom7.注解7.1注解的基本了解注解的作用为了简化代码减少代码量注解语法和本质注解的本质就是接口继承了java.lang.annotation.Annotation8.2元注解元注解可以标注注解的解释Retention注解生效的阶段Target表示注解可以使用的位置Doucumented给注解生成帮助文档Inherited该注解可以被继承注解的属性1、注解的属性就是注解中的抽象方法2、多个属性之间使用逗号分割如果多个属性中有valuevalue也要和其他方法一样写出来3、如果只需要写单个属性并且该属性名是value该属性名可以不用编写可以直接写成 元注解package org.example; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; Retention(RetentionPolicy.RUNTIME) Target({ElementType.FIELD,ElementType.METHOD,ElementType.PARAMETER})//元注解标注注解可以写在类的那些地方 public interface MyAnnotation { }注解在类中的运用public class Student { MyAnnotation//第一种属性 private String name; MyAnnotation//第二种方法 public void speak(MyAnnotation String sentence){//第三种 } }注解的多个属性使用方法代码import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; Retention(RetentionPolicy.RUNTIME) Target({ElementType.FIELD,ElementType.METHOD,ElementType.PARAMETER})//元注解标注注解可以卸载类的那些地方 public interface MyAnnotation { String[] value() default ; int getAge(); String[] getNames() default {}; }public class Student { MyAnnotation(getAge 20,getNames {,,},value )//第一种属性 private String name; MyAnnotation(getAge 0,getNames {,,},value )//第二种方法 public void speak(MyAnnotation(getAge 10,getNames {,,},value ) String sentence){//第三种 } }如果只需要写单个属性并且该属性名是value该属性名可以不用编写可以直接写成 import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; Retention(RetentionPolicy.RUNTIME) Target({ElementType.FIELD,ElementType.METHOD,ElementType.PARAMETER})//元注解标注注解可以卸载类的那些地方 public interface MyAnnotation { String[] value() default ; }public class Student { MyAnnotation( )//第一种属性 private String name; MyAnnotation( )//第二种方法 public void speak(MyAnnotation( ) String sentence){//第三种 } }
返回列表