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

你可能感兴趣的文章
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>
mysql8的安装与卸载
查看>>
MySQL8,体验不一样的安装方式!
查看>>
MySQL: Host '127.0.0.1' is not allowed to connect to this MySQL server
查看>>
Mysql: 对换(替换)两条记录的同一个字段值
查看>>
mysql:Can‘t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock‘解决方法
查看>>
MYSQL:基础——3N范式的表结构设计
查看>>
MYSQL:基础——触发器
查看>>
Mysql:连接报错“closing inbound before receiving peer‘s close_notify”
查看>>