博客
关于我
整合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/

你可能感兴趣的文章
msf
查看>>
MSSQL数据库查询优化(一)
查看>>
MSSQL数据库迁移到Oracle(二)
查看>>
MSSQL日期格式转换函数(使用CONVERT)
查看>>
MSTP多生成树协议(第二课)
查看>>
MSTP是什么?有哪些专有名词?
查看>>
Mstsc 远程桌面链接 And 网络映射
查看>>
Myeclipse常用快捷键
查看>>
MyEclipse更改项目名web发布名字不改问题
查看>>
MyEclipse用(JDBC)连接SQL出现的问题~
查看>>
mt-datetime-picker type="date" 时间格式 bug
查看>>
myeclipse的新建severlet不见解决方法
查看>>
MyEclipse设置当前行背景颜色、选中单词前景色、背景色
查看>>
Mtab书签导航程序 LinkStore/getIcon SQL注入漏洞复现
查看>>
myeclipse配置springmvc教程
查看>>
MyEclipse配置SVN
查看>>
MTCNN 人脸检测
查看>>
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>