博客
关于我
整合SSM笔记!
阅读量:634 次
发布时间:2019-03-14

本文共 7708 字,大约阅读时间需要 25 分钟。

1.导入jar包依赖

4.0.0
com.panghl
ssmbuild
1.0-SNAPSHOT
junit
junit
4.12
mysql
mysql-connector-java
8.0.21
com.mchange
c3p0
0.9.5.2
javax.servlet
servlet-api
2.5
javax.servlet.jsp
jsp-api
2.2
javax.servlet
jstl
1.2
org.mybatis
mybatis
3.5.2
org.mybatis
mybatis-spring
2.0.2
org.springframework
spring-webmvc
5.1.19.RELEASE
org.springframework
spring-jdbc
5.1.19.RELEASE
org.projectlombok
lombok
1.18.16
org.aspectj
aspectjweaver
1.9.4
log4j
log4j
1.2.17
src/main/resources
**/*.properties
**/*.xml
false
src/main/java
**/*.properties
**/*.xml
false

2.Spring整合Mybatis以及dao

创建对应的实体类以及包

 

applicationContext.xml

mybatis-config.xml

database.properties 

jdbc.driver=com.mysql.cj.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/mybatis?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=Asia/Shanghaijdbc.username=rootjdbc.password=123456

 spring-dao.xml

BookMapper.class

package com.panghl.dao;import com.panghl.entity.Books;import java.util.List;/** * @Author panghl * @Date 2021/3/29 22:02 * @Version 1.0 * @Description TODO **/public interface BooksMapper {    void add(Books books);    void delete(Integer id);    void update(Books books);    Books selectById(Integer id);    List
selectBooks();}
insert into books(bookName,bookCounts,detail) values (#{bookName},#{bookCounts},#{detail})
update books set bookCounts=#{bookCounts},bookName=#{bookName},detail=#{detail} where bookID=#{bookID}
delete from books where bookID=#{bookID}

Spring整合Service层

spring-service.xml

BookService.class

package com.panghl.service;import com.panghl.entity.Books;import java.util.List;/** * @Author panghl * @Date 2021/3/29 22:10 * @Version 1.0 * @Description TODO **/public interface BookService {    void add(Books books);    void delete(Integer id);    void update(Books books);    Books selectById(Integer id);    List
selectBooks();}
package com.panghl.service.impl;import com.panghl.dao.BooksMapper;import com.panghl.entity.Books;import com.panghl.service.BookService;import org.springframework.stereotype.Service;import java.util.List;/** * @Author panghl * @Date 2021/3/29 22:11 * @Description TODO **/@Servicepublic class BookServiceImpl implements BookService {    private BooksMapper booksMapper;    public void setBookMapper(BooksMapper bookMapper) {        this.booksMapper = bookMapper;    }    @Override    public void add(Books books) {        booksMapper.add(books);    }    @Override    public void delete(Integer id) {        booksMapper.delete(id);    }    @Override    public void update(Books books) {        booksMapper.update(books);    }    @Override    public Books selectById(Integer id) {        return booksMapper.selectById(id);    }    @Override    public List
selectBooks() { return booksMapper.selectBooks(); }}

spring整合MVC

web.xml

dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:applicationContext.xml
dispatcherServlet
/
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
namespace
utf-8
characterEncodingFilter
/*

spring-mvc.xml

BooksController.class

package com.panghl.controller;import com.panghl.entity.Books;import com.panghl.service.BookService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import java.util.List;/** * @Author panghl * @Date 2021/3/29 22:40 * @Description TODO **/@Controller@RequestMapping("/book")public class BooksController {    @Autowired    @Qualifier("bookService")    private BookService bookService;    @RequestMapping("/t1")    public String test1( Model model) {        List
books = bookService.selectBooks(); model.addAttribute("msg",books); return "test"; }}

 

 

启动tomcat测试运行:

 

 

 

 

转载地址:http://lqhoz.baihongyu.com/

你可能感兴趣的文章
MySQL-连接
查看>>
mysql-递归查询(二)
查看>>
MySQL5.1安装
查看>>
mysql5.5和5.6版本间的坑
查看>>
mysql5.5最简安装教程
查看>>
mysql5.6 TIME,DATETIME,TIMESTAMP
查看>>
mysql5.6.21重置数据库的root密码
查看>>
Mysql5.6主从复制-基于binlog
查看>>
MySQL5.6忘记root密码(win平台)
查看>>
MySQL5.6的Linux安装shell脚本之二进制安装(一)
查看>>
MySQL5.6的zip包安装教程
查看>>
mysql5.7 for windows_MySQL 5.7 for Windows 解压缩版配置安装
查看>>
Webpack 基本环境搭建
查看>>
mysql5.7 安装版 表不能输入汉字解决方案
查看>>
MySQL5.7.18主从复制搭建(一主一从)
查看>>
MySQL5.7.19-win64安装启动
查看>>
mysql5.7.19安装图解_mysql5.7.19 winx64解压缩版安装配置教程
查看>>
MySQL5.7.37windows解压版的安装使用
查看>>
mysql5.7免费下载地址
查看>>
mysql5.7命令总结
查看>>