springboot
重名又重名
这个作者很懒,什么都没留下…
展开
-
springboot教程-aop注解 @Aspect、@Before、@After、@AfterReturning、 @AfterThrowing
概述本文通过案例讲解:@Aspect、@Before、@After、@AfterReturning、 @AfterThrowing 注解的作用尤其是:@Before、@After、@AfterReturning、 @AfterThrowing 注解的执行顺序案例使用注解的方式实现aop,实现 不修改 UserSrvImpl 源代码的情况下,增加打印日志的功能创建maven工程略修改pom.xml添加依赖<dependencyManagement> <depende原创 2021-03-09 17:07:57 · 6169 阅读 · 0 评论 -
springboot教程-选择单例还是多例
单例的应用场景如 Controller、service、dao,没必要每个请求都新建一个对象,既耗费CPU、又耗费内存创建对象时耗时过多或者耗资源过多,但又经常用到的对象。没有成员变量的类频繁访问数据库或文件的类其他要求只有一个对象的场景多例的应用场景有成员变量的 service单例的问题service增加 name 成员变量,get、set方法@Servicepublic class StudentSrvImpl implements IStudentService {原创 2021-03-09 16:08:54 · 2593 阅读 · 2 评论 -
springboot教程-@Scope详解
介绍@Scope 注解用于指定作用范围源码@Target({ElementType.TYPE, ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Scope { @AliasFor("scopeName") String value() default ""; @AliasFor("value") String scopeName() defau原创 2021-03-09 14:57:07 · 2170 阅读 · 0 评论 -
springboot教程-@Qualifier详解
提出问题在使用 @Autowired 注解时,可否根据 id 注入某个对象?解决问题注解 @Autowired 搭配 @Qualifier 注解,可实现 根据 id 注入某个对象此时与 @Resource 注解功能类似源码@Target({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE, ElementType.ANNOTATION_TYPE})@Retention(Retention原创 2021-03-09 10:24:43 · 896 阅读 · 0 评论 -
springboot教程-@Autowired详解(二)有多个匹配对象时
例子如果有多个 bean对象类型,与要注入的 变量类型 匹配,会报错增加 StudentSrvImpl2其内容与 StudentSrvImpl 相同执行报错如下:提示中 studentSrvImpl、studentSrvImpl2 是哪来的?定义 StudentSrvImpl 如下://没有指定value属性,那么spring容器中默认id是 studentSrvImpl(与类同名,首字母小写)@Servicepublic class StudentSrvImpl implements原创 2021-03-09 10:23:57 · 1040 阅读 · 0 评论 -
springboot教程-@Autowired详解
上接:springboot教程-@Service详解概述本文介绍,使用 @Autowired 注解实现依赖注入源码@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD, ElementType.ANNOTATION_TYPE})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Au原创 2021-03-09 10:23:26 · 861 阅读 · 0 评论 -
springboot教程-@Service详解
介绍对于 service 层的类,在类上用 @Service 注解声明源代码@Target({ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documented@Componentpublic @interface Service { @AliasFor( annotation = Component.class ) String value() default "";}使用只能声明原创 2021-03-09 09:33:49 · 14672 阅读 · 0 评论 -
springboot教程-@ComponentScan注解
介绍指定要扫描某包下的注解源代码@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.TYPE})@Documented@Repeatable(ComponentScans.class)public @interface ComponentScan { @AliasFor("basePackages") String[] value() default {}; @AliasFor("value") St原创 2021-03-08 21:42:11 · 143 阅读 · 0 评论 -
springboot主启动类启动过程(@SpringBootApplication)
主启动类package top.malaoshi;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication //该注解标准主启动类public class Main { public static void main(String[] args) {原创 2021-03-08 16:55:50 · 2927 阅读 · 0 评论 -
springboot教程-@ComponentScan注解
介绍指定要扫描某包下的注解源代码@Retention(RetentionPolicy.RUNTIME)@Target({ElementType.TYPE})@Documented@Repeatable(ComponentScans.class)public @interface ComponentScan { @AliasFor("basePackages") String[] value() default {}; @AliasFor("value") St原创 2021-03-08 16:55:14 · 232 阅读 · 0 评论 -
springboot教程-IOC Controller的创建方式
提出问题在之前的例子中,Controller类都是可以直接使用的,我们并没有手动创建该类的对象那么 springboot 框架是如何创建 Controller 对象的?默认构造方法springboot框架,通过 默认构造方法(无参构造方法)创建对象这是 springboot 默认创建对象的方式例子创建下面Controller@Controllerpublic class HelloCtrl { public HelloCtrl(){ System.out.print原创 2021-03-08 16:54:20 · 565 阅读 · 0 评论 -
springboot教程-获取ajax提交字符串数组(@RequestParam)
介绍将请求参数封装到 List 中注意: 由于封装到 List 中,所以必须用此注解,否则会报错应用场景比如批量删除等html 代码使用jquery实现<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script><input type="button" onclick="del()" value="批量删除"><table> <tr>原创 2021-03-08 15:14:10 · 907 阅读 · 0 评论 -
springboot教程-将ajax请求中的参数封装到JavaBean中
介绍适合注册、添加页面,提交的参数较多,如下图添加学生:html创建 save_student.html ,内容如下<script type="text/javascript" src="js/jquery-1.11.0.min.js"></script>姓名:<input id="name"><br>性别:<input name="sex" value="0" type="radio">女 原创 2021-03-08 15:06:27 · 341 阅读 · 0 评论 -
springboot教程-@RequestParam详解
应用场景请求中 参数名 与 Controller方法 形参名 不同时,比如:在前后台分离式开发中,前台页面是由 前端程序员开发的,表单控件名是由 前端程序员命名的,命名为:u_phone、u_pwd后台程序员编写 Controller 时,方法的 形参名不能是:u_phone、u_pwd,因为 不符合 java命名规范,形参为:phone、password此时,前端 请求中的 参数名 和 Controller方法的形参名 不匹配,就需要用该注解,使之匹配上源码@Target({ElementT原创 2021-03-08 11:22:35 · 3758 阅读 · 0 评论 -
springboot教程-获取请求参数(参数名 与 Controller方法的形参名相同)
介绍请求中参数名 与 Controller方法的形参名相同,springboot自动将 参数值 传给 方法的形参这种方法简单好用,比较常用要求表单控件名、url中的参数名 ,必须 与 Controller方法的 形参名 相同支持的数据类型基本数据类型、字符串javabean数组获取url参数:适合5个以下的参数Controller代码:@RequestMapping("/delete")public String delete(String id){ System.o原创 2021-03-08 10:20:16 · 1113 阅读 · 0 评论 -
springboot教程-第一个controller
概述springboot框架中的 Controller,相当于增强的 servlet:接收请求(get、post、ajax)获取请求中的参数(url中的参数,post表单参数,ajax参数、上传文件)做出响应。(转发页面、重定向页面、返回json)用 Controller 代替 Servlet,不需要写 Servlet优点:更简单的代码,就可以实现更多的功能创建 controller 类package top.malaoshi.controller;import org.sprin原创 2021-03-08 10:18:57 · 582 阅读 · 0 评论 -
springboot教程-@RequestMapping源码与详解
作用url 和 处理方法 之间的映射关系源码@Target({ElementType.METHOD, ElementType.TYPE})@Retention(RetentionPolicy.RUNTIME)@Documented@Mappingpublic @interface RequestMapping { String name() default ""; @AliasFor("path") String[] value() default {};原创 2021-03-08 09:33:22 · 1202 阅读 · 0 评论