SSM框架项目的实现:
1.创建项目架构,搭建项目依赖,资源创建(我的项目架构)
2.创建数据库(数据就要自己填了哈)
3.实现java源码中的实体类
public class Paper {
private int paperId;
private String paperName;
private int paperNum;
private String paperDetail;
public int getPaperId() {
return paperId;
}
public void setPaperId(int paperId) {
this.paperId = paperId;
}
public String getPaperName() {
return paperName;
}
public void setPaperName(String paperName) {
this.paperName = paperName;
}
public int getPaperNum() {
return paperNum;
}
public void setPaperNum(int paperNum) {
this.paperNum = paperNum;
}
public String getPaperDetail() {
return paperDetail;
}
public void setPaperDetail(String paperDetail) {
this.paperDetail = paperDetail;
}
public Paper() {
}
public Paper(int paperId, String paperName, int paperNum, String paperDetail) {
this.paperId = paperId;
this.paperName = paperName;
this.paperNum = paperNum;
this.paperDetail = paperDetail;
}
public Paper(String paperName, int paperNum, String paperDetail) {
this.paperName = paperName;
this.paperNum = paperNum;
this.paperDetail = paperDetail;
}
@Override
public String toString() {
return "Paper{" +
"paperId=" + paperId +
", paperName='" + paperName + '\'' +
", paperNum=" + paperNum +
", paperDetail='" + paperDetail + '\'' +
'}';
}
}
4.实现java源码中的dao
@Component:自动注入jdbcTemplate对象,不需要再new 对象
@Service:自动注入loginDao对象,不需要new
@Component
public interface PaperDao {
//1.新增论文持久层
int insertPaper(Paper paper);
//2.删除论文持久层
int deletePaper(int paperId);
//3.修改论文持久层
int updatePaper(Paper paper);
//4.通过固定条件查询
Paper findPaperById(int paperId);
//5.全查
List<Paper> findPapersByAll();
//6.模糊查询
List<Paper> findPapersByLike(String paperName);
}
5.Mybatis是为了实现轻量级持久层,是给我们提供持久层框架,核心是将java源码SQL语句统一管理。dao-impl是有Mybatis框架取代
Spring+Mybatis整合流程
resource>>db.properties文件>>实现jdbc封装
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://127.0.0.1:3306/db_java1ssm?useSSL=true&characterEncoding=utf-8
jdbc.username=root //自己数据的用户名
jdbc.password=123456 //自己数据库的密码
resource>>log4j.properties文件>>实现日志跟踪>>配置日志路径
log4j.rootLogger=ERROR,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
spring的核心配置文件
applicationContext.xml–>>spring-dao.xml,spring-service.xml,spring-mvc.xml
**<!--spring-dao.xml-->**
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:con