发表于: 2018-06-03 21:23:39

1 1224


今天完成的事情:springboot结合mybatis的实现

                  

boot项目结构简单很多,

mvc层和spring的事情都是封装的;

web.xml,springmvc.xml ,applitionContext.xml都不需要

只用一个application.properties替代

bean的注入也很灵活

但是比spring使用方法都多也更难

 @Component是其中一种方法

@Component
public class Jedis {
private JedisPool jedis;

   public Jedis() {
}

public JedisPool getJedis() {
return jedis;
   }

public void setJedis(JedisPool jedis) {
this.jedis = jedis;
   }
}

主函数添加下面注解,注解应该有重复,还没测试, ( springboot是主函数启动,不需要去手动启动tomcat)

@Configuration   //标注一个类是配置类,spring boot在扫到这个注解时自动加载这个类相关的功能,比如前面的文章中介绍的配置AOP和拦截器时加在类上的Configuration
@EnableAutoConfiguration  //启用自动配置 该框架就能够进行行为的配置,以引导应用程序的启动与运行, 根据导入的starter-pom 自动加载配置
@ComponentScan  //扫描组件 @ComponentScan(value = "com.spriboot.controller") 配置扫描组件的路径
@SpringBootApplication
@MapperScan("com.longhang.stuDao")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
   }
}

springboot的注入bean还需要在仔细学下。应为我的redis使用全是注入bean实现的注解操作,所以要对boot的bean的注入理解透,不然就得手动写逻辑了。


springboot官方不推荐使用jsp所以使用jsp还需要在导入一些依赖实现

<!--用于编译jsp-->
<dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-jasper</artifactId>
   <!--<scope>provided</scope>-->
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-devtools</artifactId>
   <!--<scope>provided</scope>-->
   <optional>true</optional>
</dependency>

在application.properties中


# 页面默认前缀目录
spring.mvc.view.prefix=/WEB-INF/pages/
# 响应页面默认后缀
spring.mvc.view.suffix=.jsp

明天计划的事情: 注入依赖包中的类bean                         
遇到的问题:application.properties的使用没有xml熟悉,还不知怎么像xml注入依赖包中的bean。                          
收获:springboot结合mybatis的实现



返回列表 返回列表
评论

    分享到