博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Springboot整和mybatis方法一
阅读量:3949 次
发布时间:2019-05-24

本文共 4036 字,大约阅读时间需要 13 分钟。

Springboot整和mybatis方法一

使用xml文件

项目目录结构如下

在这里插入图片描述

1pom.xml文件中添加依赖(插件库下载lombok使用@Data注解)

4.0.0
org.springframework.boot
spring-boot-starter-parent
2.3.11.RELEASE
com.xxx.proj
springboot-mybatis-demo2
0.0.1-SNAPSHOT
springboot-mybatis-demo2
Demo project for Spring Boot
1.8
org.springframework.boot
spring-boot-starter-actuator
org.springframework.boot
spring-boot-starter-jdbc
org.springframework.boot
spring-boot-starter-web
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.1.4
org.springframework.boot
spring-boot-devtools
runtime
true
mysql
mysql-connector-java
runtime
org.projectlombok
lombok
true
org.springframework.boot
spring-boot-starter-test
test
org.junit.vintage
junit-vintage-engine
src/main/java
**/*.xml
false
org.springframework.boot
spring-boot-maven-plugin
org.projectlombok
lombok

2application.yml文件中添加(格式要对要有空格和缩进)

spring:  datasource:    url: jdbc:mysql:///test?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8    username: root    password: root    driver-class-name: com.mysql.jdbc.Driver

3Student实体类的创建

package com.xxx.proj.springbootmybatisdemo2.entity;import lombok.Data;@Datapublic class Student {
private Integer id; private String name; private String address;}

4StudentMapper的创建

package com.xxx.proj.springbootmybatisdemo2.mapper;import com.xxx.proj.springbootmybatisdemo2.entity.Student;import java.util.List;public interface StudentMapper {
List
findAll();}

5StudentController类的创建

package com.xxx.proj.springbootmybatisdemo2.controller;import com.xxx.proj.springbootmybatisdemo2.entity.Student;import com.xxx.proj.springbootmybatisdemo2.mapper.StudentMapper;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import java.util.List;@RestControllerpublic class StudentController {
@Autowired private StudentMapper studentMapper; @RequestMapping("/") public List
findAll() {
return studentMapper.findAll(); }}

6StudentMapper.xml文件的创建

7启动类添加注解去扫描包然后运行启动类

@SpringBootApplication@MapperScan("com.xxx.proj.springbootmybatisdemo2.mapper")

说明:访问localhost:8080,没有修改项目访问目录所以是8080,lombok插件和依赖必须有不然@Data注解就用不了

转载地址:http://nqrwi.baihongyu.com/

你可能感兴趣的文章
利用sudo命令为Ubuntu分配管理权限
查看>>
Ubuntu下几个重要apt-get命令用法与加速UBUNTU
查看>>
Ubuntu中网页各种插件安装命令
查看>>
使用tar命令备份Ubuntu系统
查看>>
ubuntu flash 文字乱码解决方案
查看>>
在ubuntu中运行exe文件
查看>>
ubuntu安装命令
查看>>
和上司沟通必备8个黄金句
查看>>
联系查看两张卡的未接电话记录
查看>>
把拒接电话作为已经接电话写到call log中
查看>>
FDN号码完全匹配
查看>>
Cosmos 拨号界面保存号码时先提示选择存储位置
查看>>
换卡或不插卡时删除通话记录
查看>>
静音模式下,来闹钟能响铃。
查看>>
调整提醒的优先级
查看>>
如何添加一个提醒
查看>>
Displaying Card Flip Animations 显示卡片翻转动画
查看>>
Zooming a View 缩放视图
查看>>
Animating Layout Changes 动画布局的更改
查看>>
Controlling Your App’s Volume and Playback 控制应用程序的音量和播放
查看>>