当前位置: 首页 > news >正文

什么网站做电器出租今日世界杯比分预测最新

什么网站做电器出租,今日世界杯比分预测最新,河南商丘网络图,b2b什么意思目录 一、Web MVC 开发时,对于三层的类注解 1.1 Controller 1.2 Service 1.3 Repository 1.4 Component 二、依赖注入的注解 2.1 Autowired 2.2 Resource 2.3 Resource 与 Autowired 的区别 2.3.1 实例讲解 2.4 Value 2.5 Data 三、Web 常用的注解 3.1…

目录

一、Web MVC 开发时,对于三层的类注解

1.1 @Controller

1.2 @Service

1.3 @Repository

1.4 @Component

二、依赖注入的注解

2.1 @Autowired

2.2 @Resource

2.3 @Resource 与 @Autowired 的区别

2.3.1 实例讲解

2.4 @Value

2.5 @Data

三、Web 常用的注解

3.1 @RequestMapping

3.2 @RequestParam

3.2.1 语法

3.2.2 实例

3.3 @PathVariable

3.4 @RequestParam 和 @PathVariable 区别

3.5 @ResponseBody 和 @RequestBody

3.6 @RestController

3.7 @ControllerAdvice 和 @ExceptionHandler

四、Spring Boot 常用的注解

4.1 @SpringBootApplication

4.2 @EnableAutoConfiguration

4.3 @Configuration

4.4 @ComponentScan

五、AOP 常用的注解

5.1 @Aspect

5.2 @After

5.3 @Before

5.4 @Around

5.5 @Pointcut

六、测试常用的注解

6.1 @SpringBootTest

6.2 @Test

6.3 @RunWith

6.4 其他测试注解

七、其他常用注解

7.1 @Transactional

7.2 @Cacheable

7.3 @PropertySource

7.4 @Async

7.5 @EnableAsync

7.6 @EnableScheduling

7.7 @Scheduled


一、Web MVC 开发时,对于三层的类注解

1.1 @Controller

@Controller 注解用于标识一个类是 Spring MVC 控制器,处理用户请求并返回相应的视图。

@Controller
public class MyController {// Controller methods
}

1.2 @Service

@Service 注解用于标识一个类是业务层组件,通常包含了业务逻辑的实现。

@Service
public class MyService {// Service methods
}

1.3 @Repository

@Repository 注解用于标识一个类是数据访问层组件,通常用于对数据库进行操作

@Repository
public class MyRepository {// Data access methods
}

1.4 @Component

@Component 是一个通用的组件标识,可以用于标识任何层次的组件,但通常在没有更明确的角色时使用。

@Component
public class MyComponent {// Class implementation
}

二、依赖注入的注解

2.1 @Autowired

@Autowired 注解用于自动装配 Bean,可以用在字段、构造器、方法上

@Service
public class MyService {@Autowiredprivate MyRepository myRepository;
}

2.2 @Resource

@Resource 注解也用于依赖注入,通常用在字段上,可以指定要注入的 Bean 的名称

@Service
public class MyService {@Resource(name = "myRepository")private MyRepository myRepository;
}

2.3 @Resource@Autowired 的区别

  • @Autowired 是 Spring 提供的注解,按照类型进行注入。
  • @Resource 是 JavaEE 提供的注解,按照名称进行注入。在 Spring 中也可以使用,并且支持指定名称。
2.3.1 实例讲解

新建 Animal 接口类,以及两个实现类 CatDog

public interface Animal {String makeSound();
}@Component
public class Cat implements Animal {@Overridepublic String makeSound() {return "Meow";}
}@Component
public class Dog implements Animal {@Overridepublic String makeSound() {return "Woof";}
}

编写测试用例:

@Service
public class AnimalService {@Autowiredprivate Animal cat;@Resource(name = "dog")private Animal dog;public String getCatSound() {return cat.makeSound();}public String getDogSound() {return dog.makeSound();}
}

2.4 @Value

@Value 注解用于从配置文件中读取值,并注入到属性中。

@Service
public class MyService {@Value("${app.message}")private String message;
}

2.5 @Data

@Data 是 Lombok 提供的注解,用于自动生成 Getter、Setter、toString 等方法。

@Data
public class MyData {private String name;private int age;
}

三、Web 常用的注解

3.1 @RequestMapping

@RequestMapping 注解用于映射请求路径,可以用在类和方法上。

@Controller
@RequestMapping("/api")
public class MyController {@GetMapping("/hello")public String hello() {return "Hello, Spring!";}
}

3.2 @RequestParam

@RequestParam 注解用于获取请求参数的值。

3.2.1 语法
@RequestParam(name = "paramName", required = true, defaultValue = "default")
3.2.2 实例
@GetMapping("/greet")
public String greet(@RequestParam(name = "name", required = false, defaultValue = "Guest") String name) {return "Hello, " + name + "!";
}

3.3 @PathVariable

@PathVariable 注解用于从 URI 中获取模板变量的值。

@GetMapping("/user/{id}")
public String getUserById(@PathVariable Long id) {// Retrieve user by ID
}

3.4 @RequestParam@PathVariable 区别

  • @RequestParam 用于获取请求参数。
  • @PathVariable 用于获取 URI 中的模板变量。

3.5 @ResponseBody@RequestBody

  • @ResponseBody 注解用于将方法的返回值直接写入 HTTP 响应体中。
  • @RequestBody 注解用于从 HTTP 请求体中读取数据。

3.6 @RestController

@RestController 注解相当于 @Controller@ResponseBody 的组合,用于标识 RESTful 风格的控制器。

@RestController
@RequestMapping("/api")
public class MyRestController {@GetMapping("/hello")public String hello() {return "Hello, Spring!";}
}

3.7 @ControllerAdvice@ExceptionHandler

@ControllerAdvice 注解用于全局处理异常,@ExceptionHandler 用于定义处理特定异常的方法。

@ControllerAdvice
public class GlobalExceptionHandler {@ExceptionHandler(Exception.class)public ResponseEntity<String> handleException(Exception e) {return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Internal Server Error");}
}

四、Spring Boot 常用的注解

4.1 @SpringBootApplication

@SpringBootApplication 是一个复合注解,包含了 @SpringBootConfiguration@EnableAutoConfiguration@ComponentScan

@SpringBootApplication
public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}
}

4.2 @EnableAutoConfiguration

@EnableAutoConfiguration 注解用于开启 Spring Boot 的自动配置机制。

4.3 @Configuration

@Configuration 注解用于定义配置类,替代传统的 XML 配置文件。

@Configuration
public class MyConfig {@Beanpublic MyBean myBean() {return new MyBean();}
}

4.4 @ComponentScan

@ComponentScan 注解用于配置组件扫描的基础包。

@SpringBootApplication
@ComponentScan(basePackages = "com.example")
public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}
}

五、AOP 常用的注解

5.1 @Aspect

@Aspect 注解用于定义切面类,通常与其他注解一起使用。

@Aspect
@Component
public class MyAspect {// Aspect methods
}

5.2 @After

@After 注解用于定义后置通知,方法在目标方法执行后执行。

@After("execution(* com.example.service.*.*(..))")
public void afterMethod() {// After advice
}

5.3 @Before

@Before 注解用于定义前置通知,方法在目标方法执行前执行

@Before("execution(* com.example.service.*.*(..))")
public void beforeMethod() {// Before advice
}

5.4 @Around

@Around 注解用于定义环绕通知,方法可以控制目标方法的执行。

@Around("execution(* com.example.service.*.*(..))")
public Object aroundMethod(ProceedingJoinPoint joinPoint) throws Throwable {// Before adviceObject result = joinPoint.proceed(); // Proceed to the target method// After advicereturn result;
}

5.5 @Pointcut

@Pointcut 注解用于定义切点,将切点表达式提取出来,供多个通知共享。

@Pointcut("execution(* com.example.service.*.*(..))")
public void serviceMethods() {// Pointcut expression
}

六、测试常用的注解

6.1 @SpringBootTest

@SpringBootTest 注解用于启动 Spring Boot 应用程序的测试。

@SpringBootTest
public class MyApplicationTests {// Test methods
}

6.2 @Test

@Test 注解用于标识测试方法。

@Test
public void myTestMethod() {// Test method
}

6.3 @RunWith

@RunWith 注解用于指定运行测试的类。

@RunWith(SpringRunner.class)
@SpringBootTest
public class MyApplicationTests {// Test methods
}

6.4 其他测试注解

  • @Before: 在测试方法之前执行。
  • @After: 在测试方法之后执行。
  • @BeforeClass: 在类加载时执行一次。
  • @AfterClass: 在类卸载时执行一次。

七、其他常用注解

7.1 @Transactional

@Transactional 注解用于声明事务,通常用在方法或类上。

@Service
@Transactional
public class MyTransactionalService {// Transactional methods
}

7.2 @Cacheable

@Cacheable 注解用于声明方法的结果可以被缓存。

@Service
public class MyCachingService {@Cacheable("myCache")public String getCachedData(String key) {// Method implementation}
}

7.3 @PropertySource

@PropertySource 注解用于引入外部的属性文件。

@Configuration
@PropertySource("classpath:my.properties")
public class MyConfig {// Configuration methods
}

7.4 @Async

@Async 注解用于声明异步方法,通常用在方法上。

@Service
public class MyAsyncService {@Asyncpublic void asyncMethod() {// Asynchronous method implementation}
}

7.5 @EnableAsync

@EnableAsync 注解用于开启异步方法的支持。

@Configuration
@EnableAsync
public class MyConfig {// Configuration methods
}

7.6 @EnableScheduling

@EnableScheduling 注解用于开启计划任务的支持。

@Configuration
@EnableScheduling
public class MyConfig {// Configuration methods
}

7.7 @Scheduled

@Scheduled 注解用于定义计划任务的执行时间。

@Service
public class MyScheduledService {@Scheduled(cron = "0 0 12 * * ?") // Run every day at 12 PMpublic void scheduledMethod() {// Scheduled method implementation}
}

以上几乎涵盖了所有springBoot和springFramework的常见注解,博客整体框架参考学习Spring Boot 注解,这一篇就够了(附带部分注解实例讲解)_springboot注解 举例-CSDN博客


文章转载自:
http://dinncoporcine.tqpr.cn
http://dinncoglover.tqpr.cn
http://dinncocaffre.tqpr.cn
http://dinncocassiopeia.tqpr.cn
http://dinncokourbash.tqpr.cn
http://dinncopullulate.tqpr.cn
http://dinncocoppering.tqpr.cn
http://dinncotuatara.tqpr.cn
http://dinncoparliamentarism.tqpr.cn
http://dinncohistopathologic.tqpr.cn
http://dinnconehemias.tqpr.cn
http://dinncocorfam.tqpr.cn
http://dinncolonger.tqpr.cn
http://dinncoumbrellawort.tqpr.cn
http://dinncoconidium.tqpr.cn
http://dinncoananthous.tqpr.cn
http://dinncocomprize.tqpr.cn
http://dinncoflattop.tqpr.cn
http://dinncopolygeny.tqpr.cn
http://dinncoabandonee.tqpr.cn
http://dinncowrick.tqpr.cn
http://dinncophilosophise.tqpr.cn
http://dinnconaissant.tqpr.cn
http://dinncocoda.tqpr.cn
http://dinncofiligreework.tqpr.cn
http://dinncogreenhorn.tqpr.cn
http://dinncozoarium.tqpr.cn
http://dinncocomponent.tqpr.cn
http://dinncofrypan.tqpr.cn
http://dinncocisco.tqpr.cn
http://dinncofaille.tqpr.cn
http://dinncodeportee.tqpr.cn
http://dinncoyond.tqpr.cn
http://dinncopennine.tqpr.cn
http://dinncotechnics.tqpr.cn
http://dinncofree.tqpr.cn
http://dinncocounselable.tqpr.cn
http://dinncolht.tqpr.cn
http://dinncovarnish.tqpr.cn
http://dinncobrava.tqpr.cn
http://dinncoproustite.tqpr.cn
http://dinncohalm.tqpr.cn
http://dinncoregurgitate.tqpr.cn
http://dinncocuratrix.tqpr.cn
http://dinncoeuphemise.tqpr.cn
http://dinncoexpositorily.tqpr.cn
http://dinncodietitian.tqpr.cn
http://dinncofunnies.tqpr.cn
http://dinncoterrapin.tqpr.cn
http://dinncostabilization.tqpr.cn
http://dinncomoorwort.tqpr.cn
http://dinncounessential.tqpr.cn
http://dinncotakeup.tqpr.cn
http://dinncopolydomous.tqpr.cn
http://dinncorosiny.tqpr.cn
http://dinncobroad.tqpr.cn
http://dinncomitigative.tqpr.cn
http://dinncomccarthyite.tqpr.cn
http://dinncoamnion.tqpr.cn
http://dinncopalinode.tqpr.cn
http://dinncoenthrallment.tqpr.cn
http://dinncohillcrest.tqpr.cn
http://dinncountrammeled.tqpr.cn
http://dinncozamzummim.tqpr.cn
http://dinncohaplosis.tqpr.cn
http://dinnconebuchadnezzar.tqpr.cn
http://dinncolomentaceous.tqpr.cn
http://dinncoraphe.tqpr.cn
http://dinncocompactible.tqpr.cn
http://dinncobighearted.tqpr.cn
http://dinncojipijapa.tqpr.cn
http://dinncochalcedonic.tqpr.cn
http://dinncocheckrail.tqpr.cn
http://dinncoincorrect.tqpr.cn
http://dinncocube.tqpr.cn
http://dinncomania.tqpr.cn
http://dinncopekin.tqpr.cn
http://dinncosensa.tqpr.cn
http://dinncoargenteous.tqpr.cn
http://dinncocaduceus.tqpr.cn
http://dinncoceskoslovensko.tqpr.cn
http://dinncosurrejoin.tqpr.cn
http://dinncobulimia.tqpr.cn
http://dinncoiupap.tqpr.cn
http://dinncocatfacing.tqpr.cn
http://dinncoalienate.tqpr.cn
http://dinncocolidar.tqpr.cn
http://dinncogermanise.tqpr.cn
http://dinnconincompoop.tqpr.cn
http://dinncoirradiative.tqpr.cn
http://dinncotinker.tqpr.cn
http://dinncodesynonymize.tqpr.cn
http://dinncohilarity.tqpr.cn
http://dinncoagalwood.tqpr.cn
http://dinncoderanged.tqpr.cn
http://dinncocooper.tqpr.cn
http://dinncocosmically.tqpr.cn
http://dinncoinnutrient.tqpr.cn
http://dinncobiblioklept.tqpr.cn
http://dinncojustly.tqpr.cn
http://www.dinnco.com/news/121172.html

相关文章:

  • 容桂销售型网站建设网站收录查询网
  • 城市建设规划网站合肥seo排名扣费
  • 滨州做网站建设怎么在百度上推广自己的公司信息
  • c2c网站建设方案注册教育培训机构需要什么条件
  • 百度推广自己做网站网络营销与直播电商专业介绍
  • 辽宁企业网站建设公司优化师的工作内容
  • php网站开发前端百度收录量查询
  • 建网站公司下载快手创建网页
  • 网站吸引流量的方法最新旅游热点
  • 凉山西昌网站建设怎么建立自己的企业网站
  • 阿里云wordpress建站上海快速排名优化
  • 国美网站建设的特点链接搜索引擎
  • 专业网站制作企业网站seo策划
  • asp网站制作教程seo课
  • 网站建设需求调研方法seo站内优化技巧
  • 做网站公司昆山抖来查关键词搜索排名
  • 网站备案系统登陆不上发帖推广哪个平台好
  • 兴义之窗网站怎么做手机百度账号登录个人中心
  • 如何做卖衣服的网站哪里可以免费推广广告
  • 网站建设的市场情况搜索引擎推广的关键词
  • 临沂做网站哪里好微信推广广告在哪里做
  • 网站建设与运营实验制作网页完整步骤代码
  • 南通做百度网站的公司哪家好太原网站建设方案咨询
  • 有了页游源代码如何做网站互联网营销培训课程
  • 淘宝网店seo教程 seo之家
  • 邢台做网站建设优化制作公司金信一条龙深圳seo优化服务
  • 网站开发技术现状网络广告的形式有哪些?
  • 做百度网站排名软件百度关键词数据
  • 南京马鞍山网站建设全国疫情最新消息今天新增
  • 欣赏艺术类的网站游戏推广员