使用SpringBoot+MyBatis框架做查询操作

一.在你建立的工程下创建 Module 选择Spring initializr创建。
使用Spring Boot+MyBatis框架做查询操作

成都创新互联公司是专业的沿河网站建设公司,沿河接单;提供网站设计、成都网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行沿河网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

二.在Type处选择: Maven Project(项目的构建工具)
使用Spring Boot+MyBatis框架做查询操作

三.创建依赖时勾上web,mybatis,MySQL(这个看你个人需要吧,可以自主选择)
使用Spring Boot+MyBatis框架做查询操作

使用Spring Boot+MyBatis框架做查询操作

建立好的项目结构如下:
使用Spring Boot+MyBatis框架做查询操作

注意:application.properties和application.yml是同一个东西,均为项目的核心配置文件

内容如下:

#连接数据库
spring.datasource.url=jdbc:mysql://localhost:3306/smbms
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driverClassName=com.mysql.jdbc.Driver
#引入mybatis的配置文件
mybatis:
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.example.sprboot.pojo

    相应的pom.xml文件
  <?xml version="1.0" encoding="UTF-8"?>

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

com.example
springboot
0.0.1-SNAPSHOT
jar

springboot
Demo project for Spring Boot


    org.springframework.boot
    spring-boot-starter-parent
    2.0.5.RELEASE
     


    UTF-8
    UTF-8
    1.8


    
    
        org.springframework.boot
        spring-boot-starter-web
    
    
    
        org.springframework.boot
        spring-boot-starter-test
        test
    
    
    
        org.mybatis.spring.boot
        mybatis-spring-boot-starter
        1.3.0
    
    
    
        mysql
        mysql-connector-java
    
    
    
        com.alibaba
        fastjson
        1.2.49
    
    
    
        org.springframework.boot
        spring-boot-starter-thymeleaf
    


    
        
            org.springframework.boot
            spring-boot-maven-plugin
        
    

相应的接口UserMapper如下:

@Repository
public interface UserMapper {
List getList();
}

service如下:

public interface UserService {
List getList();
}

impl如下:

@Service
public class UserServiceImpl implements UserService {@Resource
br/>@Resource
br/>@Override
getList() {
return userMapper.getList();
}
}

在resources中建一个文件夹mapper里面放mapper.xml文件,代码如下:




















工号用户名姓名性别生日电话地址创建时间

此处有一个th标签,需要引入一个
并在pom.xml中引入对应的jar包(html中不能使用jstl表达式)

大家可以扩展一下thymeleaf的知识

控制器代码如下:

@Controller
public class UserController {@Resource
br/>@Resource
br/>@RequestMapping("/")
List list=userService.getList();
model.addAttribute("users",list);
System.out.println(list);
return "/index.html";
}
}

注:在调通的时候,可能会报很多的错,基本上都是注解的使用出错,希望各位能够细心点


分享名称:使用SpringBoot+MyBatis框架做查询操作
文章地址:http://lszwz.com/article/jhjhch.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款