1. springboot 和springmvc下的注解完全一样(新增了一些有用的)

常用的注解如下:

@Controller

@RestController= @Controller + @ResponseBody

四大请求方法注注解

getMapping, postMapping, deleteMapping, DeleteMapping

(getMapping= RequestMapping + method=RequestMethod.GET)表示该方法支持get请求

事务注解 @Transaction

2. springboot 使用jsp

1. 在springboot使用jsp, 需要在pom文件中引入支持jsp的解析包如下:

<!--引入Spring Boot内嵌的Tomcat对JSP的解析包-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- servlet依赖的jar包start -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<!-- servlet依赖的jar包start --> <!-- jsp依赖jar包start -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- jsp依赖jar包end --> <!--jstl标签依赖的jar包start -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!--jstl标签依赖的jar包end -->

2. 在application里面配置前后缀

spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp

3. 如果是idea用户, 需要在pom里面配置一下build, 防止出现404 not found

<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
<resource>
<directory>src/main/webapp</directory>
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>

3. springboot 集成mybatis

1. 首先在pom里面添加相关依赖

<!-- 加载mybatis整合springboot -->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency> <!-- MySQL的jdbc驱动包 -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

2、在Springboot的核心配置文件 application.properties 中配置MyBatis的Mapper.xml文件所在位置:

mybatis.mapper-locations=classpath:com/bjpowernode/springboot/mapper/*.xml

3、在Springboot的核心配置文件application.properties中配置数据源:

spring.datasource.username=root
spring.datasource.password=root21322
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://ip:3036/db1?useUnicode=true&characterEncoding=utf8&useSSL=false

4、在MyBatis的Mapper接口中添加@Mapper注解 或者 在运行的主类上添加 @MapperScan("com.bjpowernode.springboot.mapper") 注解包扫描

4. springboot 事务支持非常简单

1、在入口类(application类)中使用注解 @EnableTransactionManagement 开启事务支持;

2、在访问数据库的Service方法上添加注解 @Transactional 即可;

(04) springboot 下的springMVC和jsp和mybatis的更多相关文章

  1. SpringSecurity在Springboot下使用的初步体验

    SpringSecurity曾经在十年前非常火热,只要是做权限系统,当时几乎非用它不可,记得是在XML文件里一堆的配置.曾几何时,Shiro冒了出来,以其简洁和轻量的风格慢慢地捕获了众多码农的心,从此 ...

  2. javaConfig下的springmvc配置

    javaConfig下的springmvc配置 一.静态资源过滤 XML的配置 <mvc:resources mapping="/**" location="/&q ...

  3. 关于SpringBoot下template文件夹下html页面访问的一些问题

    springboot整合了springmvc的拦截功能.拦截了所有的请求.默认放行的资源是:resources/static/ 目录下所有静态资源.(不走controller控制器就能直接访问到资源) ...

  4. SpringBoot:扩展SpringMVC、定制首页、国际化

    目录 扩展使用SpringMVC 如何扩展SpringMVC 为何这么做会生效(原理) 全面接管SpringMVC 首页实现 页面国际化 SpringBoot扩展使用SpringMVC.使用模板引擎定 ...

  5. SpringBoot第九集:整合JSP和模板引擎Freemarker/Thymeleaf(2020最新最易懂)

    SpringBoot第九集:整合JSP和模板引擎(2020最新最易懂) 当客户通过前端页面提交请求后,我们以前是怎么做的?后端接收请求数据,处理请求,把响应结果交给模板引擎JSP,最后将渲染后的JSP ...

  6. Ubuntu16.04 LTS下apt安装WireShark

    Ubuntu16.04 LTS下apt安装WireShark 安装与配置 首先通过apt安装WireShark: $ sudo apt install wireshark 会同时安装许多的依赖包,其中 ...

  7. Ubuntu 14.04 LTS 下 android 2.3.5 源码编译过程

    Ubuntu 14.04 LTS 下 android 2.3.5 源码编译过程   在新的Ubuntu 64位系统下去编译早期的安卓源码是会出现很多问题的,因为64位系统在安装完成后,很多32位的兼容 ...

  8. Ubuntu 12.04环境下配置Postgresql和phppgadmin

    Ubuntu 12.04环境下配置Postgresql 9.1 和phppgadmin 本系列文章由ex_net(张建波)编写,转载请注明出处. http://blog.csdn.net/zjianb ...

  9. Ubuntu13.04 Eclipse下编译安装Hadoop插件及使用小例

    Ubuntu13.04 Eclipse下编译安装Hadoop插件及使用小例 一.在Eclipse下编译安装Hadoop插件 Hadoop的Eclipse插件现在已经没有二进制版直接提供,只能自己编译. ...

随机推荐

  1. drf 多表

    https://www.django-rest-framework.org/  官方站 https://www.django-rest-framework.org/tutorial/quickstar ...

  2. 分享一个基于ssm框架下的webService接口开发

    首先肯定是导入相关jar包 cxf-core-3.1.9.jar cxf-rt-bindings-soap-3.1.9.jar cxf-rt-bindings-xml-3.1.9.jar cxf-rt ...

  3. Flutter进阶—点击、拖动和其他手势

    Flutter中的手势系统有两个层次.第一层具有原始指针事件,其描述了穿过屏幕的指针(例如触摸.鼠标和触控笔)的位置和移动.第二层具有手势,其描述由一个或多个指针移动组成的语义动作. 指针指针代表用户 ...

  4. markdown code test - markdown code test - markdown code test - markdown code test

    目录 主要代码 bottom cc 主要代码 <div class="tocCol1 js-toc"></div> <a>bc</a> ...

  5. 在Pycharm中使用Pandas时输出结果中列被省略的解决办法

    在使用pycharm学习pandas的过程中我发现好多时候会发生不能输出所有列的情况,上网搜了一下,发现解决的办法是使用一个输出控制的函数. 在下面的代码中我们只是输出starbucks_store_ ...

  6. Easy to Remember Color Guide for Non-Designers

    Notes: I'm not a designer. This is what i've self-learnt over the years because i couldn't afford go ...

  7. maven 安装本地jar

    mvn install:install-file -Dfile=D:/open-api-sdk-2.0.jar -DgroupId=com.jd.open -DartifactId=jd-api-sd ...

  8. 使用Mongo进行分页

    MongoDB’s pipeline aggregation is – like most things in application development these days – confusi ...

  9. 趋势:flex和grid使布局更简单

    前言:记不久前面试的时候,面试官问我平时用什么布局方式,我非常耿直的说 div+css,利用position,float等布局,这就是非常传统的布局方式,通常都要写比较多的css代码:前几天在知乎上看 ...

  10. winform使用log4.net

    因为我最近负责的Winform项目,好多都用到了这个log4net的日志功能,开发程序对数据一般都要求做到雁过留痕,所以日志对于我们程序员是不可或缺.因此我把对log4net的使用做一个记录总结,以便 ...