编程语言
首页 > 编程语言> > Java学习的第二十四天:SSM框架

Java学习的第二十四天:SSM框架

作者:互联网

SSM图书管理系统:

!(C:\Users\sky\AppData\Roaming\Typora\typora-user-images\image-20210708144651608.png)

数据库

image-20210708145337929

图书分类表

##

image-20210708151353805

 

 

 

整合spring

创建po

package com.xiao.po;

import java.io.Serializable;

//图书类的一个对象:
//实现虚拟化
public class ClassInfo implements Serializable {

   private Integer id;
   private String name;
   private String renarks;


   public Integer getId() {
       return id;
  }

   public void setId(Integer id) {
       this.id = id;
  }

   public String getName() {
       return name;
  }

   public void setName(String name) {
       this.name = name;
  }

   public String getRenarks() {
       return renarks;
  }

   public void setRenarks(String renarks) {
       this.renarks = renarks;
  }
}

创建dao

package com.xiao.dao;

//查询所以的用户信息

import com.xiao.po.ClassInfo;

import java.util.List;

public interface ClassInfoDao {
//查询所有的图类型信息

   List<ClassInfo> queryClassInfoAll();
}

创建service

package com.xiao.service;

import com.xiao.po.ClassInfo;

import java.util.List;

public interface ClassInfoService {
   List<ClassInfo> queryClassInfoAll();
}

创建ServiceImpl

package com.xiao.service.Impl;

import com.xiao.po.ClassInfo;
import com.xiao.service.ClassInfoService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("classInfoService")
public class ClassInfoServiceImpl implements ClassInfoService {
   @Override
   public List<ClassInfo> queryClassInfoAll() {
       System.out.println("查询到了所以的图书类型》》》》");
       return null;
  }
}

配置sepring。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:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!--开启注解扫描,处理servlce层和dao层,controller不处理-->

    <context:component-scan base-package="com.xiao" >
<!--         p配置不扫描的-->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>

    </context:component-scan>

</beans>

 

测试层demo:

package com.xiao.demo;

import com.xiao.po.ClassInfo;
import com.xiao.service.ClassInfoService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

//c测试spring是否能执行:
public class TestDemo {
   @Test
   public void testspring(){
//       或者spring容器:
     ApplicationContext app=  new ClassPathXmlApplicationContext("spring.xml");

//     获取bean
     ClassInfoService info=(ClassInfoService) app.getBean("classInfoService");
        info.queryClassInfoAll();
  }
}

标签:Java,xiao,springframework,SSM,第二十四,org,import,com,public
来源: https://www.cnblogs.com/954321xx/p/14988805.html