springboot跳转html_使用Spring Boot+MyBatis框架做查询操作

一.在你建立的工程下创建 Module 选择Spring initializr创建。

d7f5fc20a8edc42bbb0d72707e9c99b8.png

二.在Type处选择: Maven Project(项目的构建工具)

3e59c66b988e083485e9bd07176a3dfa.png

三.创建依赖时勾上web,mybatis,mysql(这个看你个人需要吧,可以自主选择)

3677d15acefe9c8f32a57673eb81b5ba.png
4d2fa3dbec14068ed119af92cb174207.png

建立好的项目结构如下:

09801fa313c344a370c8ed5762acd7d1.png

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

内容如下:

#连接数据库spring.datasource.url=jdbc:mysql://localhost:3306/smbmsspring.datasource.username=rootspring.datasource.password=1234spring.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"?>4.0.0com.example springboot 0.0.1-SNAPSHOTjarspringbootDemo project for Spring Bootorg.springframework.boot spring-boot-starter-parent 2.0.5.RELEASEUTF-8UTF-81.8org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test testorg.mybatis.spring.boot mybatis-spring-boot-starter 1.3.0mysql mysql-connector-java com.alibaba fastjson 1.2.49org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-maven-plugin 

相应的接口UserMapper如下:

@Repositorypublic interface UserMapper { List getList();}

service如下:

public interface UserService { List getList();}

impl如下:

@Servicepublic class UserServiceImpl implements UserService { @Resource private UserMapper userMapper; @Override public List getList() { return userMapper.getList(); }}

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

 select * from smbms_user

在templates文件夹中建html文件(注意:Spring Boot中不能跳转到.jsp文件,所以只能用html)

核心代码如下:

此处有一个th标签,需要引入一个

并在pom.xml中引入对应的jar包(html中不能使用jstl表达式)

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

控制器代码如下:

@Controllerpublic class UserController { @Resource private UserService userService;@RequestMapping("/") public String getStuinforList(HttpServletRequest request, Model model){ List list=userService.getList(); model.addAttribute("users
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值