mybatis理解

 

 

 

如何创建模板

mybatis核心配置文件

set注入

mabatis的编程步骤

1.读取核心配置文件

2.创建SqlSessionFactory工厂

3.使用工厂生产SqlSession对象

4.使用SqlSession对象创建接口代理对象

面试题集合

spring

 

Spring Bean装配方式

 

Spring框架中有哪些不同类型的事件?

spring中的bean的生命周期

FileSystemResource 和 ClassPathResource 有何区别

FileSystemResource 中需要给出spring-config.xml文件在你项目中的相对路径或者绝对路径。在ClassPathResource中spring会在ClassPath中自动搜寻配置文件,所以要把ClassPathResource 文件放在ClassPath下。

如果将spring-config.xml保存在了src文件夹下的话,只需给出配置文件的名称即可,因为src文件夹是默认。

简而言之,ClassPathResource在环境变量中读取配置文件,FileSystemResource在配置文件中读取配置文件。

Set注入的三种方式

Spring 基于注解的配置

从 Spring 2.5 开始就可以使用注解来配置依赖注入。而不是采用 XML 来描述一个 bean 连线,你可以使用相关类,方法或字段声明的注解,将 bean 配置移动到组件类本身。

注解:就是一个类,使用@注解名称 开发中:使用注解 取代 xml配置文件。 创建Bean @Component取代<bean class=""> @Component(“id”) 取代 <bean id="" class="">

web开发,提供3个@Component注解衍生注解(功能一样)取代<bean class="">

@Repository :dao层 @Service:service层 @Controller:web层 注解使用前提,添加命名空间,让spring扫描含有注解类

配置 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<!-- 组件扫描,扫描含有注解的类 -->
<context:component-scan base-package="com.cc.study.annotation"></context:component-scan>

</beans> schema命名空间

User
@Component("userId")
public class User {
    private String username;
    private Address address;

public String getUsername() {
    return username;
}
​
public void setUsername(String username) {
    this.username = username;
}
​
public Address getAddress() {
    return address;
}
​
public void setAddress(Address address) {
    this.address = address;
}

}

测试
 @Test
    public void demo01(){
        String xmlPath = "annotation.xml";
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        User user = (User) applicationContext.getBean("userId");
        System.out.println(user);
    }

结果发现报错了,报错如下:

1 2 3 4 5 6 7 结果发现报错了,报错如下:

java.lang.IllegalArgumentException at org.springframework.asm.ClassReader.<init>(Unknown Source) at org.springframework.asm.ClassReader.<init>(Unknown Source) at org.springframework.asm.ClassReader.<init>(Unknown Source) at org.springframework.core.type.classreading.SimpleMetadataReader.<init>(SimpleMetadataReader.java:52) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:80) at org.springframework.core.type.classreading.CachingMetadataReaderFactory.getMetadataReader(CachingMetadataReaderFactory.java:101) at org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:76) at org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:298) at org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300) at org.springframework.context.annotation.ConfigurationClassParser.getImports(ConfigurationClassParser.java:300) at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:230) at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:153) at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:130) at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:285) at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:223) at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:630) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at com.cc.study.annotation.TestAnnotation.demo01(TestAnnotation.java:16) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) at org.junit.runners.ParentRunner.run(ParentRunner.java:236) at org.junit.runner.JUnitCore.run(JUnitCore.java:157) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

然后我试了一下把Spring的版本改成4.0,把JDK改为1.8即可

<dependencies> <!-- 4个核心(beans、core、context、expression) --> <!-- https://mvnrepository.com/artifact/org.springframework/spring-context --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.2.0.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-beans --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>4.2.0.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-core --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.2.0.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-expression --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>4.2.0.RELEASE</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.7</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build>

测试结果:

依赖注入 依赖注入,给私有字段设置,也可以给setter方法设置

普通值注入 使用@Value

User
@Component("userId")
public class User {
    @Value("Kevin")
    private String username;
    private Address address;

public String getUsername() {
    return username;
}
​
public void setUsername(String username) {
    this.username = username;
}
​
public Address getAddress() {
    return address;
}
​
public void setAddress(Address address) {
    this.address = address;
}

}

引用值注入 方式1:按照【类型】注入 @Autowired

Address @Component public class Address { @Value("北京") private String addr; @Value("112") private String tel;

public String getAddr() {
    return addr;
}
​
public void setAddr(String addr) {
    this.addr = addr;
}
​
public String getTel() {
    return tel;
}
​
public void setTel(String tel) {
    this.tel = tel;
}

}

User @Component("userId") public class User { @Value("Kevin") private String username; @Autowired private Address address;

public String getUsername() {
    return username;
}
​
public void setUsername(String username) {
    this.username = username;
}
​
public Address getAddress() {
    return address;
}
​
public void setAddress(Address address) {
    this.address = address;
}

}

测试
 @Test
    public void demo03(){
        String xmlPath = "annotation.xml";
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        User user = (User) applicationContext.getBean("userId");
        System.out.println(user.getUsername());
        System.out.println(user.getAddress().getAddr());
        System.out.println(user.getAddress().getTel());
    }

方式2:按照【名称】注入1

@Autowired

@Qualifier(“名称”)

Address
@Component("addressId")
public class Address {
    @Value("北京")
    private String addr;
    @Value("112")
    private String tel;

public String getAddr() {
    return addr;
}

public void setAddr(String addr) {
    this.addr = addr;
}

public String getTel() {
    return tel;
}

public void setTel(String tel) {
    this.tel = tel;
}

}

User

@Component("userId")
public class User {
    @Value("Kevin")
    private String username;
    @Autowired
    @Qualifier("addressId")
    private Address address;

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public Address getAddress() {
    return address;
}

public void setAddress(Address address) {
    this.address = address;
}

}

方式3:按照【名称】注入2 @Resource(name=“名称”)

User

@Component("userId")
public class User {
    @Value("Kevin")
    private String username;

@Resource(name = "addressId")
private Address address;

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public Address getAddress() {
    return address;
}

public void setAddress(Address address) {
    this.address = address;
}

}

测试

@Test
    public void demo03(){
        String xmlPath = "annotation.xml";
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        User user = (User) applicationContext.getBean("userId");
        System.out.println(user.getUsername());
        System.out.println(user.getAddress().getAddr());
        System.out.println(user.getAddress().getTel());
    }

生命周期 初始化:@PostConstruct 销毁:@PreDestroy

User

@Component("userId")
public class User {
    @Value("Kevin")
    private String username;

@Resource(name = "addressId")
private Address address;

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public Address getAddress() {
    return address;
}

public void setAddress(Address address) {
    this.address = address;
}

@PostConstruct
public void init(){
    System.out.println("初始化");
}
@PreDestroy
public void destroy(){
    System.out.println("销毁");
}

}

测试

 @Test
    public void demo04(){
        String xmlPath = "annotation.xml";
        AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        User user = (User) applicationContext.getBean("userId");
        System.out.println(user.getUsername());
        System.out.println(user.getAddress().getAddr());
        System.out.println(user.getAddress().getTel());
        applicationContext.close();
    }

作用域

@Scope(“prototype”) 多例

User

@Component("userId")
@Scope("prototype")
public class User {
    @Value("Kevin")
    private String username;

@Resource(name = "addressId")
private Address address;

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

public Address getAddress() {
    return address;
}

public void setAddress(Address address) {
    this.address = address;
}

@PostConstruct
public void init(){
    System.out.println("初始化");
}
@PreDestroy
public void destroy(){
    System.out.println("销毁");
}

}

测试

@Test
    public void demo05(){
        String xmlPath = "annotation.xml";
        AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
        User user1 = (User) applicationContext.getBean("userId");
        User user2 = (User) applicationContext.getBean("userId");
        System.out.println(user1);
        System.out.println(user2);
    }
    
    
  自动装配的方式  https://blog.csdn.net/cckevincyh/article/details/89766454?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522163272868916780255218306%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=163272868916780255218306&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduend~default-1-89766454.first_rank_v2_pc_rank_v29&utm_term=%E6%B3%A8%E8%A7%A3%E8%A3%85%E9%85%8D&spm=1018.2226.3001.4187

Spring基于注解装配Bean

1.springboot定义

简化spring配置以配置及开发

并且内嵌web应用容器

这样避免开发人员过多的框架的关注,而过多的精力

放在业务中

2.SpringBoot的作用

SpringBoot框架。

核心是自动配置,只要有相应的jar包,spring就会帮助我们自动配置,而无需我们

以前我们使用spring框架一样要做很多配置,

能配置不能满足我们的要求,我们能够由自己配置来替换这些自动配置的。此外还继承了系统监控的功能,这些都可以帮我们快速搭建js项,可以直接使用。

SpringBoot面试题

19.为什么集合类没有实现Cloneable和Serializable接口?

克隆(cloning)或者是序列化(serialization)的语义和含义是跟具体的实现相关的。因此,应该由集合类的具体实现来决定如何被克隆或者是序列化。

20.什么是迭代器(Iterator)?

Iterator接口提供了很多对集合元素进行迭代的方法。每一个集合类都包含了可以返回迭代器实例的

迭代方法。迭代器可以在迭代的过程中删除底层集合的元素。

22.快速失败(fail-fast)和安全失败(fail-safe)的区别是什么?

Iterator的安全失败是基于对底层集合做拷贝,因此,它不受源集合上修改的影响。java.util包下面的所有的集合类都是快速失败的,而java.util.concurrent包下面的所有的类都是安全失败的。快速失败的迭代器会抛出

ConcurrentModificationException异常,而安全失败的迭代器永远不会抛出这样的异常。

115道Java经典面试题(面中率最高、最全)_fcyh的博客-CSDN博客_java经典面试题 Java面试题

数据库的ACID指定数据库的事物(一致性,隔离性,)

aop原理

spring用代理类包裹切面,把他们织入到Spring管理的bean中。也就是说代理类伪装成目标类,它会截取对目标类中方法的调用,让调用者对目标类的调用都先变成调用伪装类,伪装类中就先执行了切面,再把调用转发给真正的目标bean。

  现在可以自己想一想,怎么搞出来这个伪装类,才不会被调用者发现(过JVM的检查,JAVA是强类型检查,哪里都要检查类型)。

  1.实现和目标类相同的接口,我也实现和你一样的接口,反正上层都是接口级别的调用,这样我就伪装成了和目标类一样的类(实现了同一接口,咱是兄弟了),也就逃过了类型检查,到java运行期的时候,利用多态的后期绑定(所以spring采用运行时),伪装类(代理类)就变成了接口的真正实现,而他里面包裹了真实的那个目标类,最后实现具体功能的还是目标类,只不过伪装类在之前干了点事情(写日志,安全检查,事物等)。

  这就好比,一个人让你办件事,每次这个时候,你弟弟就会先出来,当然他分不出来了,以为是你,你这个弟弟虽然办不了这事,但是他知道你能办,所以就答应下来了,并且收了点礼物(写日志),收完礼物了,给把事给人家办了啊,所以你弟弟又找你这个哥哥来了,最后把这是办了的还是你自己。但是你自己并不知道你弟弟已经收礼物了,你只是专心把这件事情做好。

  顺着这个思路想,要是本身这个类就没实现一个接口呢,你怎么伪装我,我就压根没有机会让你搞出这个双胞胎的弟弟,那么就用第2种代理方式,创建一个目标类的子类,生个儿子,让儿子伪装我

  2.生成子类调用,这次用子类来做为伪装类,当然这样也能逃过JVM的强类型检查,我继承的吗,当然查不出来了,子类重写了目标类的所有方法,当然在这些重写的方法中,不仅实现了目标类的功能,还在这些功能之前,实现了一些其他的(写日志,安全检查,事物等)。

  这次的对比就是,儿子先从爸爸那把本事都学会了,所有人都找儿子办事情,但是儿子每次办和爸爸同样的事之前,都要收点小礼物(写日志),然后才去办真正的事。当然爸爸是不知道儿子这么干的了。这里就有件事情要说,某些本事是爸爸独有的(final的),儿子学不了,学不了就办不了这件事,办不了这个事情,自然就不能收人家礼了。

  前一种兄弟模式,spring会使用JDK的java.lang.reflect.Proxy类,它允许Spring动态生成一个新类来实现必要的接口,织入通知,并且把对这些接口的任何调用都转发到目标类。

  后一种父子模式,spring使用CGLIB库生成目标类的一个子类,在创建这个子类的时候,spring织入通知,并且把对这个子类的调用委托到目标类。

  相比之下,还是兄弟模式好些,他能更好的实现松耦合,尤其在今天都高喊着面向接口编程的情况下,父子模式只是在没有实现接口的时候,也能织入通知,应当做一种例外。

Spring MVC的理解

Spring MVC是Spring提供的一个强大而灵活的web框架。借助于注解,Spring MVC提供了几乎是POJO的开发模式,使得控制器的开发和测试更加简单。这些控制器一般不直接处理请求,而是将其委托给Spring上下文中的其他bean,通过Spring的依赖注入功能,这些bean被注入到控制器中

Spring MVC主要由DispatcherServlet、处理器映射、处理器(控制器)、视图解析器、视图组成。他的两个核心是两个核心:

处理器映射:选择使用哪个控制器来处理请求 视图解析器:选择结果应该如何渲染

通过以上两点,Spring MVC保证了如何选择控制处理请求和如何选择视图展现输出之间的松耦合。

2.SpringMVC运行原理

(1) Http请求:客户端请求提交到DispatcherServlet。 (2) 寻找处理器:由DispatcherServlet控制器查询一个或多个HandlerMapping,找到处理请求的Controller。 (3) 调用处理器:DispatcherServlet将请求提交到Controller。 (4)(5)调用业务处理和返回结果:Controller调用业务逻辑处理后,返回ModelAndView。 (6)(7)处理视图映射并返回模型: DispatcherServlet查询一个或多个ViewResoler视图解析器,找到ModelAndView指定的视图。 (8) Http响应:视图负责将结果显示到客户端。

3.SpringMVC接口解释 (1)DispatcherServlet接口: Spring提供的前端控制器,所有的请求都有经过它来统一分发。在DispatcherServlet将请求分发给Spring Controller之前,需要借助于Spring提供的HandlerMapping定位到具体的Controller。 (2)HandlerMapping接口: 能够完成客户请求到Controller映射。 (3)Controller接口: 需要为并发用户处理上述请求,因此实现Controller接口时,必须保证线程安全并且可重用。 Controller将处理用户请求,这和Struts Action扮演的角色是一致的。一旦Controller处理完用户请求,则返回ModelAndView对象给DispatcherServlet前端控制器,ModelAndView中包含了模型(Model)和视图(View)。 从宏观角度考虑,DispatcherServlet是整个Web应用的控制器;从微观考虑,Controller是单个Http请求处理过程中的控制器,而ModelAndView是Http请求过程中返回的模型(Model)和视图(View)。 (4)ViewResolver接口: Spring提供的视图解析器(ViewResolver)在Web应用中查找View对象,从而将相应结果渲染给客户。

4.DispatcherServlet: 是整个Spring MVC的核心。它负责接收HTTP请求组织协调Spring MVC的各个组成部分。其主要工作有以下三项: (1)截获符合特定格式的URL请求。 (2)初始化DispatcherServlet上下文对应WebApplicationContext,并将其与业务层、持久化层的WebApplicationContext建立关联。 (3)初始化Spring MVC的各个组成组件,并装配到DispatcherServlet中。

为什么Java语言的开发者,把String类定义为final的呢?

因为只有当字符串是不可变的,字符串池才有可能实现。字符串池的实现可以在运行时节约很多heap空间,因为不同的字符串变量都指向池中的同一个字符串。但如果字符串是可变的

因为字符串是不可变的,所以是多线程安全的,同一个字符串实例可以被多个线程共享。这样便不用因为线程安全问题而使用同步。字符串自己便是线程安全的。

方法重写的规则:

参数列表、方法名、返回值类型必须完全一致;

构造方法不能被重写;

声明为 final 的方法不能被重写;

声明为 static 的方法不存在重写(重写和多态联合才有意义);

访问权限不能比父类更低;

重写之后的方法不能抛出更宽泛的异常;

抽象类(abstract class)和接口(interface)有什么异同?

相同点:

● 不能够实例化

● 可以将抽象类和接口类型作为引用类型

● 一个类如果继承了某个抽象类或者实现了某个接口都需要对其中的抽象方法全部进行实现,否则该类仍然需要被声明为抽象类;

说出最常见的5个RuntimeException?

● java.lang.NullPointerException 空指针异常;出现原因:调用了未经初始化的对象或者是不存在的对象。

● java.lang.ClassNotFoundException 指定的类找不到;出现原因:类的名称和路径加载错误;通常都是程序试图通过字符串来加载某个类时可能引发异常。

● java.lang.NumberFormatException 字符串转换为数字异常;出现原因:字符型数据中包含非数字型字符。

● java.lang.IndexOutOfBoundsException 数组角标越界异常,常见于操作数组对象时发生。

● java.lang.IllegalArgumentException 方法传递参数错误。

● java.lang.ClassCastException 数据类型转换异常。

● java.lang.NoClassDefFoundException 未找到类定义错误。

● SQLException SQL 异常,常见于操作数据库时的 SQL 语句错误。

● java.lang.InstantiationException 实例化异常。

● java.lang.NoSuchMethodException 方法不存在异常。

HashSet 里的元素是不能重复的, 那用什么方法来区分重复与否呢?

往集合在添加元素时,调用 add(Object)方法的时候,首先会调用Object的 hashCode()方法判断hashCode 是否已经存在,如不存在则直接插入元素;如果已存在则调用Object对象的 equals()方法判断是否返回 true,如果为true则说明元素已经存在,如为false则插入元素。

SpringMVC中的Tomcat的配置

IDEA 新建Spring MVC项目、环境配置、Tomcat配置_Hern(宋兆恒)的博客-CSDN博客_spring项目配置tomcat

Spring MVC和Struts2的区别

  1. Spring MVC 基于方法开发,Struts2 基于类开发。

  2. Spring MVC 会将 URL 信息与 Controller 类的某个方法进行映射,生成 Handler 对象,该对象中只包含了一个 method 方法。方法执行结束之后,形参数据也会被销毁

  3. 而在使用 Struts2 框架进行开发时,Action 类中所有方法使用的请求参数都是 Action 类中的成员变量,随着方法变得越来越多,就很难分清楚 Action 中那么多的成员变量到底是给哪一个方法使用的,整个 Action 类会变得十分混乱。

  4. Spring MVC 可以进行单例开发,Struts2 无法使用单例

    Struts2 由于只能通过类的成员变量接受参数

URLBasedViewResolver

  1. UrlBasedViewResolver 是对 ViewResolver 的一种简单实现,主要提供了一种拼接 URL 的方式来解析视图。

2.UrlBasedViewResolver 通过 prefix 属性指定前缀,suffix 属性指定后缀

InternalResourceViewResolver

  1. InternalResourceViewResolver 为“内部资源视图解析器”,是日常开发中最常用的视图解析器类型。它是 URLBasedViewResolver 的子类,拥有 URLBasedViewResolver 的一切特性

Spring MVC传递参数

  • 通过实体 Bean 接收请求参数

  • Bean 的属性名称必须与请求参数名称相同

  • 通过处理方法的形参接收请求参数

  • 形参名称与请求参数名称完全相同

  • 通过 HttpServletRequest 接收请求参数

  • HttpServletRequest 接收请求参数适用于 get 和 post 提交请求方式

  • 通过 @PathVariable 接收 URL 中的请求参数

  • @PathVariable 获取 URL 中的参数

  • 通过 @RequestParam 接收请求参数

  • @RequestParam 注解指定其对应的请求参数

  • 通过 @ModelAttribute 接收请求参数

Spring MVC @Autowired和@Service注解

@Autowired 注解属于 org.springframework.beans.factory. annotation 包,可以对类成员变量、方法及构造函数进行标注,完成自动装配的工作。

@Service 注解属于 org.springframework.stereotype 包,会将标注类自动注册到 Spring 容器中

Spring MVC @ModelAttribute注解

Controller 中使用 @ModelAttribute(用来将请求参数绑定到 Model 对象。) 时,有以下几种应用情况。

  • 应用在方法

  • 应用在方法的参数

  • 应用在方法上,并且方法也使用了 @RequestMapping

单列模式

懒汉式:默认不会实例化,什么时候用什么时候new。

public class Lazy{ private Lazy(){} //默认不会实例化,什么时候用什么时候new private static Lazy lazy=null; public static synchronized Lazy getInstance(){ if(lazy==null){ lazy=new Lazy(); } return lazy; } } 饿汉式:类加载的时候就实例化,并且创建单例对象。

public class Hungry{ private Hungry(){} // 类加载的时候就实例化,并且创建单例对象 private static final Hungry hungry=new Hungry(); public static Hungry getInstance(){ return hungry; } }

SpringMVC

类型转化器

实体中的注解pojo

@Component 交个spring容器管理

@Lazy懒加载

@PostConstruct对象的初始化

@PostDestory对象的销毁

Ajax请求

请求方式

@(function(){

//发起请求

$.ajax({

type:"post", //请求方式

url:"", //请求地址

data:{ //请求时带的参数

},

dataType: "jsonp", //期望服务区返回的数据的类型

success:funtion(data){//请求成功,会返回数据data



},

error:function(data){

alert("请求错误");

}

})

})

添加参数

根据条件进行值返回

 <el-form-item label="学期" prop="tName"> 

​          <el-select v-model="form.tName" placeholder="请选择" @change="aaaaa($event)">
​              <el-option
​                v-for="item in options"
​                :key="item.id"
​                :label="item.label"
​                :value="item.value">
​              </el-option>
​            </el-select>
​        </el-form-item>

方法参数

 aaaaa(value){
      console.log(value);
       tremClassTrem(value).then(response => {
         this.tremClass=response
         this.loading = false;  
         this.tremClass = this.tremClass.filter(item => item != null)
         this.tremClass = Array.from(new Set(this.tremClass))
         console.log(this.tremClass)
         this.$forceUpdate();
      });
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值