栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Spring Boot JSP视图和 MyBatis 对 MySQL 数据库进行 CRUD 操作

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Boot JSP视图和 MyBatis 对 MySQL 数据库进行 CRUD 操作

项目目录结构

 数据库

create table post
 
(
 
    id int not null primary key auto_increment,
 
    title varchar(500)  null,
 
    content varchar(500)  null,
 
    userId int null,
 
    createDate Timestamp null
 
)

pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.6.7
         
    
    com.cos
    crud
    0.1
    crud
    Demo project for Spring Boot

    
        1.8
    

    

        
            org.apache.tomcat
            tomcat-jasper
            9.0.62
        


        
            javax.servlet
            jstl
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.2.2
        

        
            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
                
            
        
    

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


application.properties

server.port = 8080
server.servlet.context-path = /

spring.mvc.view.prefix = /WEB-INF/views/
spring.mvc.view.suffix = .jsp

spring.datasource.url = jdbc:mysql://localhost:3306/db?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
spring.datasource.username = root
spring.datasource.password = root
logging.level.com.cos.crud=debug

resources/mapper/post.xml




	
		SELECT * FROM post ORDER BY id DESC
	
	

updateForm.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>


    
        
        Insert title here
    
    

        


运行日志


  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _    
( ( )___ | '_ | '_| | '_ / _` |    
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |___, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.7)

2022-05-01 20:05:47.571  INFO 10344 --- [  restartedMain] com.cos.crud.CrudApplication             : Starting CrudApplication using Java 1.8.0_202 on x220win10 with PID 10344 (F:SpringBoot-MyBatis-MySql-CRUD-masterSpringBoot-MyBatis-MySql-CRUD-mastertargetclasses started by Administrator in F:SpringBoot-MyBatis-MySql-CRUD-masterSpringBoot-MyBatis-MySql-CRUD-master)
2022-05-01 20:05:47.571 DEBUG 10344 --- [  restartedMain] com.cos.crud.CrudApplication             : Running with Spring Boot v2.6.7, Spring v5.3.19
2022-05-01 20:05:47.571  INFO 10344 --- [  restartedMain] com.cos.crud.CrudApplication             : No active profile set, falling back to 1 default profile: "default"
2022-05-01 20:05:47.938  INFO 10344 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-05-01 20:05:47.939  INFO 10344 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-05-01 20:05:47.940  INFO 10344 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.62]
2022-05-01 20:05:48.066  INFO 10344 --- [  restartedMain] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2022-05-01 20:05:48.069  INFO 10344 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-05-01 20:05:48.070  INFO 10344 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 497 ms
2022-05-01 20:05:48.243  INFO 10344 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2022-05-01 20:05:48.254  INFO 10344 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-05-01 20:05:48.259  INFO 10344 --- [  restartedMain] com.cos.crud.CrudApplication             : Started CrudApplication in 0.732 seconds (JVM running for 1709.904)
2022-05-01 20:05:48.261  INFO 10344 --- [  restartedMain] .ConditionEvaluationDeltaLoggingListener : Condition evaluation unchanged
2022-05-01 20:05:53.865  INFO 10344 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-05-01 20:05:53.866  INFO 10344 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2022-05-01 20:05:53.867  INFO 10344 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
2022-05-01 20:05:53.871  INFO 10344 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-3 - Starting...
2022-05-01 20:05:53.879  INFO 10344 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-3 - Start completed.
2022-05-01 20:05:53.884 DEBUG 10344 --- [nio-8080-exec-1] c.c.c.repository.PostRepository.findAll  : ==>  Preparing: SELECT * FROM post ORDER BY id DESC
2022-05-01 20:05:53.899 DEBUG 10344 --- [nio-8080-exec-1] c.c.c.repository.PostRepository.findAll  : ==> Parameters: 
2022-05-01 20:05:53.915 DEBUG 10344 --- [nio-8080-exec-1] c.c.c.repository.PostRepository.findAll  : <==      Total: 1
2022-05-01 20:06:14.389 DEBUG 10344 --- [nio-8080-exec-3] c.c.crud.repository.PostRepository.save  : ==>  Preparing: INSERT INTO post(title,content,userId,createDate) VALUES(?,?,?,now())
2022-05-01 20:06:14.392 DEBUG 10344 --- [nio-8080-exec-3] c.c.crud.repository.PostRepository.save  : ==> Parameters: 测试(String), 测试(String), 0(Integer)
2022-05-01 20:06:14.409 DEBUG 10344 --- [nio-8080-exec-3] c.c.crud.repository.PostRepository.save  : <==    Updates: 1
2022-05-01 20:06:14.416 DEBUG 10344 --- [nio-8080-exec-4] c.c.c.repository.PostRepository.findAll  : ==>  Preparing: SELECT * FROM post ORDER BY id DESC
2022-05-01 20:06:14.417 DEBUG 10344 --- [nio-8080-exec-4] c.c.c.repository.PostRepository.findAll  : ==> Parameters: 
2022-05-01 20:06:14.418 DEBUG 10344 --- [nio-8080-exec-4] c.c.c.repository.PostRepository.findAll  : <==      Total: 2
2022-05-01 20:08:01.636 DEBUG 10344 --- [nio-8080-exec-6] c.c.c.r.PostRepository.findById          : ==>  Preparing: SELECt * FROM post WHERe id=?
2022-05-01 20:08:01.636 DEBUG 10344 --- [nio-8080-exec-6] c.c.c.r.PostRepository.findById          : ==> Parameters: 7(Integer)
2022-05-01 20:08:01.638 DEBUG 10344 --- [nio-8080-exec-6] c.c.c.r.PostRepository.findById          : <==      Total: 1
2022-05-01 20:08:10.831 DEBUG 10344 --- [nio-8080-exec-7] c.c.c.r.PostRepository.findById          : ==>  Preparing: SELECt * FROM post WHERe id=?
2022-05-01 20:08:10.831 DEBUG 10344 --- [nio-8080-exec-7] c.c.c.r.PostRepository.findById          : ==> Parameters: 7(Integer)
2022-05-01 20:08:10.832 DEBUG 10344 --- [nio-8080-exec-7] c.c.c.r.PostRepository.findById          : <==      Total: 1
2022-05-01 20:08:26.843 DEBUG 10344 --- [nio-8080-exec-8] c.c.c.repository.PostRepository.update   : ==>  Preparing: UPDATE post SET title=?, content=? WHERe id=?
2022-05-01 20:08:26.844 DEBUG 10344 --- [nio-8080-exec-8] c.c.c.repository.PostRepository.update   : ==> Parameters: 测试777(String), 测试777(String), 7(Integer)
2022-05-01 20:08:26.863 DEBUG 10344 --- [nio-8080-exec-8] c.c.c.repository.PostRepository.update   : <==    Updates: 1
2022-05-01 20:08:26.870 DEBUG 10344 --- [nio-8080-exec-8] c.c.c.repository.PostRepository.findAll  : ==>  Preparing: SELECT * FROM post ORDER BY id DESC
2022-05-01 20:08:26.870 DEBUG 10344 --- [nio-8080-exec-8] c.c.c.repository.PostRepository.findAll  : ==> Parameters: 
2022-05-01 20:08:26.872 DEBUG 10344 --- [nio-8080-exec-8] c.c.c.repository.PostRepository.findAll  : <==      Total: 2
2022-05-01 20:08:41.819 DEBUG 10344 --- [nio-8080-exec-9] c.c.c.r.PostRepository.findById          : ==>  Preparing: SELECt * FROM post WHERe id=?
2022-05-01 20:08:41.820 DEBUG 10344 --- [nio-8080-exec-9] c.c.c.r.PostRepository.findById          : ==> Parameters: 6(Integer)
2022-05-01 20:08:41.821 DEBUG 10344 --- [nio-8080-exec-9] c.c.c.r.PostRepository.findById          : <==      Total: 1
2022-05-01 20:08:43.610 DEBUG 10344 --- [io-8080-exec-10] c.c.c.repository.PostRepository.delete   : ==>  Preparing: DELETE FROM post WHERe id=?
2022-05-01 20:08:43.610 DEBUG 10344 --- [io-8080-exec-10] c.c.c.repository.PostRepository.delete   : ==> Parameters: 6(Integer)
2022-05-01 20:08:43.629 DEBUG 10344 --- [io-8080-exec-10] c.c.c.repository.PostRepository.delete   : <==    Updates: 1
2022-05-01 20:08:43.636 DEBUG 10344 --- [nio-8080-exec-1] c.c.c.repository.PostRepository.findAll  : ==>  Preparing: SELECT * FROM post ORDER BY id DESC
2022-05-01 20:08:43.636 DEBUG 10344 --- [nio-8080-exec-1] c.c.c.repository.PostRepository.findAll  : ==> Parameters: 
2022-05-01 20:08:43.639 DEBUG 10344 --- [nio-8080-exec-1] c.c.c.repository.PostRepository.findAll  : <==      Total: 1

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/855479.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号