一.用IDEA创建项目

1.添加pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.aibabel</groupId>
<artifactId>boot1</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope> </dependency> -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.6</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!--druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.4</version>
</dependency>
<!--commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<!--shiro -->
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-spring</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.2.0</version>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.50</version>
</dependency>
<!-- mybatis代码生成器 -->
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.7</version>
</dependency> <dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies> </project>

2.分别写三层代码

javabean

package com.aibabelx.entity;

public class Student {

    private   String xh;
private String xm;
private double fs; public String getXh() {
return xh;
} public void setXh(String xh) {
this.xh = xh;
} public String getXm() {
return xm;
} public void setXm(String xm) {
this.xm = xm;
} public double getFs() {
return fs;
} public void setFs(double fs) {
this.fs = fs;
}
}

2.mapper接口

package com.aibabelx.mapper;

import com.aibabelx.entity.Student;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper; import java.util.List;
@Mapper
public interface StudentMapper extends BaseMapper<Student> { public int getSum();
public List<Student> getMax();
public List<Student> getSax(); }

3.service接口

package com.aibabelx.service;

import com.aibabelx.entity.Student;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.stereotype.Service; import java.util.List; public interface StudentService extends IService<Student> {
public int getSum();
public List<Student> getMax();
public List<Student> getSax();
}

4.service 实现类

package com.aibabelx.service.impl;

import com.aibabelx.entity.Student;
import com.aibabelx.mapper.StudentMapper;
import com.aibabelx.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import java.util.List; @Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService { @Autowired
public StudentMapper studentMapper; @Override
public int getSum() {
return studentMapper.getSum();
} @Override
public List<Student> getMax() {
return studentMapper.getMax();
} @Override
public List<Student> getSax() {
return studentMapper.getSax();
}
}

5.controller

package com.aibabelx.controller;

import com.aibabelx.entity.Student;
import com.aibabelx.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView; import java.util.List; @Controller
public class StudentController { @Autowired
public StudentService studentService; @RequestMapping("/index")
public ModelAndView index(){
int n = studentService.getSum();
List< Student > getMax=studentService.getMax();
List<Student> getSax=studentService.getSax(); return new ModelAndView("index.jsp")
.addObject("max",getMax)
.addObject("sax",getSax)
.addObject("n",n);
}
}

6.mapper的xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.aibabelx.mapper.StudentMapper"> <!-- 通用查询映射结果 -->
<resultMap id="ItemBaseResultMap" type="com.aibabelx.entity.Student">
<id column="xh" property="xh" />
<result column="xm" property="xm" />
<result column="fs" property="fs" /> </resultMap> <select id="getSum" resultType="Integer" >
SELECT COUNT(xh)
FROM Student </select>
<select id="getMax" resultType="Student">
SELECT xh,xm,fs from student WHERE fs =(SELECT MAX(fs) from student) </select>
<select id="getSax" resultType="Student">
SELECT xh,xm,fs from student WHERE fs =(SELECT min(fs) from student) </select> </mapper>

7.application.properties

server.port =9999
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8
#jsp config
spring.mvc.view.prefix=/WEB-INF/views/
#spring.mvc.view.suffix: .jsp # DataSource
spring.datasource.url=jdbc:mysql://localhost/aiplay?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql = true mybatis-plus.typeAliasesPackage=com.aibabelx.entity
mybatis-plus.mapperLocations=classpath*:mapper/*.xml
logging.level.com.looedu.mapper=debug
mybatis-plus.check-config-location:true
mybatis-plus.configuration.log-impl:org.apache.ibatis.logging.stdout.StdOutImpl server.port =9999
spring.http.encoding.force=true
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
server.tomcat.uri-encoding=UTF-8
#jsp config
spring.mvc.view.prefix=/WEB-INF/views/
#spring.mvc.view.suffix: .jsp # DataSource
spring.datasource.url=jdbc:mysql://localhost/aiplay?characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.show-sql = true mybatis-plus.typeAliasesPackage=com.aibabelx.entity
mybatis-plus.mapperLocations=classpath*:mapper/*.xml
logging.level.com.looedu.mapper=debug
mybatis-plus.check-config-location:true
mybatis-plus.configuration.log-impl:org.apache.ibatis.logging.stdout.StdOutImpl

8.index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head> <body> ${n} <c:forEach items="${max}" var="student" >
${student.xh}<br> ${student.xm}<br> ${student.fs}<br>
</c:forEach> <c:forEach items="${sax}" var="student" >
${student.xh}<br> ${student.xm}<br> ${student.fs}<br>
</c:forEach> </body>
</html>

项目结构如下

项目地址

springboot系列五:springboot整合mybatisplus jsp的更多相关文章

  1. Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)

    前言 由于在开发My Blog项目时使用了大量的技术整合,针对于部分框架的使用和整合的流程没有做详细的介绍和记录,导致有些朋友用起来有些吃力,因此打算在接下来的时间里做一些基础整合的介绍,当然,可能也 ...

  2. springboot系列五、springboot常用注解使用说明

    一.controller相关注解 1.@Controller 控制器,处理http请求. 2.@RespController Spring4之后新加的注解,原来返回json需要@ResponseBod ...

  3. SpringBoot系列五:SpringBoot错误处理(数据验证、处理错误页、全局异常)

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念: SpringBoot 错误处理 2.具体内容 在之前的程序里面如果一旦出现了错误之后就会出现一堆的大白板,这个白板会 ...

  4. SpringBoot(五)-- 整合Spring的拦截器

    一.步骤 1.创建我们自己的拦截器类并实现 HandlerInterceptor 接口. 2.创建一个Java类继承WebMvcConfigurerAdapter,并重写 addInterceptor ...

  5. SpringBoot学习(五)-->SpringBoot的核心

    SpringBoot的核心 1.入口类和@SpringBootApplication Spring Boot的项目一般都会有*Application的入口类,入口类中会有main方法,这是一个标准的J ...

  6. SPRING-BOOT系列之SpringBoot快速入门

    今天 , 正式来介绍SpringBoot快速入门 : 可以去如类似 https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/refer ...

  7. SPRING-BOOT系列之SpringBoot的诞生及其和微服务的关系

    转载自 : https://www.cnblogs.com/ityouknow/p/9034377.html 微服务架构 微服务的诞生并非偶然,它是在互联网高速发展,技术日新月异的变化以及传统架构无法 ...

  8. SpringBoot整合系列--整合MyBatis-plus

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/10125279.html SpringBoot整合MyBatis-plus 步骤 第一步: ...

  9. SpringBoot系列(五)Mybatis整合完整详细版

    SpringBoot系列(五)Mybatis整合 目录 mybatis简介 项目创建 entity dao service serviceImpl mapper controller 1. Mybat ...

随机推荐

  1. codefforces 877B

    B. Nikita and stringtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inpu ...

  2. μC/OS-III---I笔记13---中断管理

    中断管理先看一下最常用的临界段进入的函数:进入临界段 OS_CRITICAL_ENTER() 退出临界段OS_CRITICAL_EXIT()他们两个的宏是这样的. 在使能中断延迟提交时: #if OS ...

  3. Git常用命令速查表 & Git Basics & github : release 发布!

    Git常用命令速查表 & Git Basics  & github : release  发布! Git常用命令速查表: 1 1 1 1 1 http://git-scm.com/bo ...

  4. Jamstack Conf 2020

    Jamstack Conf 2020 Jamstack Conf Virtual https://jamstackconf.com/virtual/ Conf Schedule https://jam ...

  5. 微信小程序-导航 & 路由

    微信小程序-导航 & 路由 页面跳转 页面路由 页面栈, 框架以栈的形式维护了当前的所有页面. https://developers.weixin.qq.com/miniprogram/dev ...

  6. ES2021 & Pipeline operator (|>) / 管道运算符 |>

    ES2021 & Pipeline operator (|>) / 管道运算符 |> demo "use strict"; /** * * @author xg ...

  7. flutter practical

    flutter practical https://flutterchina.club/ https://github.com/flutterchina/flutter-in-action https ...

  8. Kyle Tedford :人,一定要懂得转弯

    每个人都渴望成功,但成功之路不仅仅只有一条. 有的时候,有一条路人满为患,每个人都挤破脑袋想要过去,然而能过去者,却寥寥无几.但有的人,却知道适时转弯,在新的道路上,摸索前进,最终通往成功. 最近,星 ...

  9. CPU飙升的问题

    本文转载自CPU飙升的问题 问题发现 事情是这样的,最近小码仔负责的项目预定今天凌晨2点上进行版本更新.前几天测试小姐姐对网站进行压力测试,观察服务的CPU.内存.load.RT.QPS等各种指标. ...

  10. Linux解压缩相关命令

    Linux解压缩相关命令 运行级别: 0:关机 1:单用户 2:多用户无网络连接 3:多用户有网络连接 4:系统保留 5:图形界面 6:系统重启 通过init[0123456]来切换不同的运行级别 g ...