美文网首页
springboot and vue 测试开发三-其他常用

springboot and vue 测试开发三-其他常用

作者: 小眼睛的露鹿酱 | 来源:发表于2022-02-12 15:00 被阅读0次
图片.png

1. Component

/springboot   假设是一个容器 没有使用@Component  这个类就没有进入springboot容器
@Component
//现在已经将这个类注入到 springboot了  现在可以被使用了  可以在其他的类中使用
public class questionServiceImpl implements questionservice {
}

2. Autowired

Autowired 用于将一个bean 注入到其他bean

@RestController   //Spring会转换返回值并将日写入http相应
//@RequestMapping("get")  //用于类和防范,在方法级别时, 处理http的各种防范
public class getListController {
    @Autowired   //向这个bean中注入其他bean  questionServiceImpl
    private questionServiceImpl questionServiceimpl;

    @GetMapping("get")
    public String get(){
        return   "hello get";
    }
@Component
//现在已经将这个类注入到 springboot了  现在可以被使用了  可以在其他的类中使用
public class questionServiceImpl implements questionservice {

    @Override
    public String getQuestion3(questionDto question){
        System.out.println(question.getQuestionName());
        System.out.println(question.getQuestionType());
        return question.getQuestionName()+" "+question.getQuestionName();
    }

}
  @Autowired   //向这个bean中注入其他bean  questionServiceImpl
    private questionServiceImpl questionServiceimpl;

    @PostMapping("getquestion4impl")
    public String getQuestion3(@RequestBody questionDto  q){
        return "getquestion4impl >>"+  questionServiceimpl.getQuestion3(q);

    }
图片.png

3. @Repository

4. @Service

//springboot   假设是一个容器 没有使用@Component  这个类就没有进入springboot容器
//@Component
@Service   //用于service的bean  是Component的子层
//现在已经将这个类注入到 springboot了  现在可以被使用了  可以在其他的类中使用
public class questionServiceImpl implements questionservice {

    @Override
    public String getQuestion3(questionDto question){
        System.out.println(question.getQuestionName());
        System.out.println(question.getQuestionType());
        return question.getQuestionName()+" "+question.getQuestionName();
    }

}

5. Configuration

用于声明springboot的配置文件类

6. Value(${key})

 @Value("${config.key}")   //如果没有${} 就会将config.key 赋值给key
    private String key;
    @GetMapping("get")
    public String get(){
        return   "hello get"+key;
    }
图片.png

7. Bean: 声明其为bean实例, 常和Configuration 配合使用

相关文章

网友评论

      本文标题:springboot and vue 测试开发三-其他常用

      本文链接:https://www.haomeiwen.com/subject/eplzkrtx.html