博客
关于我
整合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 CONCAT函数
查看>>
multiprocessing.Pool:map_async 和 imap 有什么区别?
查看>>
MySQL Connector/Net 句柄泄露
查看>>
multiprocessor(中)
查看>>
mysql CPU使用率过高的一次处理经历
查看>>
Multisim中555定时器使用技巧
查看>>
MySQL CRUD 数据表基础操作实战
查看>>
multisim变压器反馈式_穿过隔离栅供电:认识隔离式直流/ 直流偏置电源
查看>>
mysql csv import meets charset
查看>>
multivariate_normal TypeError: ufunc ‘add‘ output (typecode ‘O‘) could not be coerced to provided……
查看>>
MySQL DBA 数据库优化策略
查看>>
multi_index_container
查看>>
MySQL DBA 进阶知识详解
查看>>
Mura CMS processAsyncObject SQL注入漏洞复现(CVE-2024-32640)
查看>>
Mysql DBA 高级运维学习之路-DQL语句之select知识讲解
查看>>
mysql deadlock found when trying to get lock暴力解决
查看>>
MuseTalk如何生成高质量视频(使用技巧)
查看>>
mutiplemap 总结
查看>>
MySQL DELETE 表别名问题
查看>>
MySQL Error Handling in Stored Procedures---转载
查看>>