org.projectlombok
lombok
mysql
mysql-connector-java
runtime
org.springframework.boot
spring-boot-starter-jdbc
com.baomidou
mybatis-plus-boot-starter
3.2.0
javax.servlet
javax.servlet-api
javax.servlet
jstl
org.apache.tomcat.embed
tomcat-embed-jasper
org.springframework.boot
spring-boot-maven-plugin

编辑YML文件

===========================================================================
server:
port: 8090 #定义端口
servlet:
context-path: / #定义项目的发布路径
spring:
datasource:
#driver-class-name: com.mysql.cj.jdbc.Driver springboot程序采用默认的配置
url: jdbc:mysql://127.0.0.1:3306/jtdb?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
username: root
password: root
mvc: #引入mvn配置
view:
prefix: /WEB-INF/ # /默认代表根目录 src/main/webapp
suffix: .jsp
mybatis-plus:
#定义别名包
type-aliases-package: com.jt.pojo
#加载user标签的mapper文件
mapper-locations: classpath:/mybatis/mappers/*.xml
#开启驼峰映射
configuration:
map-underscore-to-camel-case: true
#引入日志信息.
logging:
level:
com.jt.mapper: debug

查询user列表数据

==============================================================================

【要求】

用户通过 http://localhost :8090/findAll请求。跳转到userList.jsp页面中,并且展现user表中的所有数据,以MP方式查询

编辑UserController

====================================================================================
package com.jt.controller;
import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
//@RestController //json 字符串本身 不经过视图解析器
@Controller
public class UserController {
@Autowired
private UserService userService;
/**
  • 需求:用户通过http://localhost:8090/findAll
  • 跳转页面路径:userList.jsp
  • 页面取值信息: el表达式:${userList} 从域中取值.
在页面跳转之前应该将userList数据保存到域中 key就是userList.
*/
@RequestMapping(“/findAll”)
public String findAll(Model model){ //利用model对象将数据保存到request对象中.
//1.查询数据库 获取list集合信息
List userList = userService.findAll();
model.addAttribute(“userList”,userList);
System.out.println(userList);
return “userList”;
}
}
编辑UserService
=================================================================================
package com.jt.service;
import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class UserServiceImpl implements UserService{
@Autowired
private UserMapper userMapper;
@Override
public List findAll() {
return userMapper.selectList(null);
}
}