1.解决编写错误
![](https://i-blog.csdnimg.cn/blog_migrate/42b4fb2d4d91b08ba6dca1b0612086a3.png)
2.注解
2.1 MySpringBootApplication
package com.czxy.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author 辰逸
* @description
*/
@Target(ElementType.TYPE) //只能修饰类
@Retention(RetentionPolicy.RUNTIME) //策略 运行时(内存)
public @interface MySpringBootApplication {
}
2.2 MyMapper
package com.czxy.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author 辰逸
* @description
*/
@Target(ElementType.TYPE) //只能修饰类
@Retention(RetentionPolicy.RUNTIME) //策略 运行时(内存)
public @interface MyMapper {
}
2.3 MySelect
package com.czxy.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author 辰逸
* @description
*/
@Target(ElementType.METHOD) //只能修饰方法
@Retention(RetentionPolicy.RUNTIME) //策略 运行时(内存)
public @interface MySelect {
public String value() ; //注解参数
}
2.4 MyService
package com.czxy.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author 辰逸
* @description
*/
@Target(ElementType.TYPE) //只能修饰类
@Retention(RetentionPolicy.RUNTIME) //策略 运行时(内存)
public @interface MyService {
}
2.5 MyRestController
package com.czxy.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author 辰逸
* @description
*/
@Target(ElementType.TYPE) //只能修饰类
@Retention(RetentionPolicy.RUNTIME) //策略 运行时(内存)
public @interface MyRestController {
}
2.6 MyRequestMapping
package com.czxy.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author 辰逸
* @description
*/
@Target(ElementType.TYPE) //只能修饰类
@Retention(RetentionPolicy.RUNTIME) //策略 运行时(内存)
public @interface MyRequestMapping {
public String value(); //参数
}
2.7 MyGetMapping
package com.czxy.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author 辰逸
* @description
*/
@Target(ElementType.METHOD) //只能修饰方法
@Retention(RetentionPolicy.RUNTIME) //策略 运行时(内存)
public @interface MyGetMapping {
// public String value() default "" ; //注解参数
}
2.8 MyPostMapping
package com.czxy.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author 辰逸
* @description
*/
@Target(ElementType.METHOD) //只能修饰方法
@Retention(RetentionPolicy.RUNTIME) //策略 运行时(内存)
public @interface MyPostMapping {
// public String value() default "" ; //注解参数
}
3.Spring Boot核心类
package com.czxy.boot;
import com.czxy.annotation.MySpringBootApplication;
/**
* @author 辰逸
* @description
*/
public class MySpringApplication {
/**
* 整个程序的入口
* @param appClass
* @param args
*/
public static void run(Class appClass, String[] args) {
// 1)校验启动类是否有 @MySpringBootApplication注解
boolean hasBootApp = appClass.isAnnotationPresent(MySpringBootApplication.class);
if(!hasBootApp) {
throw new RuntimeException(appClass + "没有添加@MySpringBootApplication注解");
}
System.out.println("正常运行");
}
}