博客
关于我
整合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之性能优化--索引的使用
查看>>
mysql之旅【第一篇】
查看>>
Mysql之索引选择及优化
查看>>
mysql之联合查询UNION
查看>>
mysql之连接查询,多表连接
查看>>
mysql乐观锁总结和实践 - 青葱岁月 - ITeye博客
查看>>
mysql也能注册到eureka_SpringCloud如何向Eureka中进行注册微服务-百度经验
查看>>
mysql乱码
查看>>
Mysql事务。开启事务、脏读、不可重复读、幻读、隔离级别
查看>>
MySQL事务与锁详解
查看>>
MySQL事务原理以及MVCC详解
查看>>
MySQL事务及其特性与锁机制
查看>>
mysql事务理解
查看>>
MySQL事务详解结合MVCC机制的理解
查看>>
MySQL事务隔离级别:读未提交、读已提交、可重复读和串行
查看>>
MySQL事务隔离级别:读未提交、读已提交、可重复读和串行
查看>>
webpack css文件处理
查看>>
mysql二进制包安装和遇到的问题
查看>>
MySql二进制日志的应用及恢復
查看>>