首页 > 其他分享 >2024/03/06

2024/03/06

时间:2024-03-06 22:46:01浏览次数:15  
标签:03 springbootwebquickstart 06 equals 2024 emp import com itheima

今日在软件学习上所花的时间大概就3小时多左右。

今日的编写的代码行数算上数据库大概300多行。

发表博客一篇。

今天主要学习了springboot中的三层架构加上分层解藕,使用ioc容器管理和DI分配来完成项目在运行时的对象的实例化对象的填充。

package com.itheima.springbootwebquickstart.controller;

import com.itheima.springbootwebquickstart.dao.impl.EmpDaoA;
import com.itheima.springbootwebquickstart.pojo.Emp;
import com.itheima.springbootwebquickstart.pojo.Result;
import com.itheima.springbootwebquickstart.service.EmpService;
import com.itheima.springbootwebquickstart.service.impl.EmpServiceA;
import com.itheima.springbootwebquickstart.utils.XmlParserUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
//controller层接受请求响应数据
@RestController
public class EmpController {
//    private EmpService empService=new EmpServiceA();
    //耦合性太强需要解耦
    @Resource(name="empServiceB")//jdk提供的

//    @Qualifier("empServiceA")//指定装配的类型
//    @Autowired
    private EmpService empService;


    @RequestMapping("/listEmp")
    public Result list()
    {
//        DAO层
//        String file=this.getClass().getClassLoader().getResource("emp.xml").getFile();
//        System.out.println(file);
//        //从emp.xml中获取数据并解析
//        List<Emp> empList=XmlParserUtils.parse(file, Emp.class);

//        Service层
//        empList.stream().forEach(emp->{
//            String gender=emp.getGender();
//            if("1".equals("gender"))
//            {
//                emp.setGender("男");
//            } else if ("2".equals(gender)) {
//                emp.setGender("女");
//            }
//            String job=emp.getJob();
//            if("1".equals(job))
//            {
//                emp.setGender("讲师");
//            } else if ("2".equals(job)) {
//                emp.setGender("班主任");
//            } else if ("3".equals(job)) {
//                emp.setJob("就业指导");
//            }
//        });




        //响应数据
        List<Emp> empList= empService.listEmp();
        return Result.success(empList);
    }
}
package com.itheima.springbootwebquickstart.service;

import com.itheima.springbootwebquickstart.pojo.Emp;

import java.util.List;
//service进行逻辑处理
public interface EmpService {
    public List<Emp> listEmp();
}
package com.itheima.springbootwebquickstart.service.impl;

import com.itheima.springbootwebquickstart.dao.EmpDao;
import com.itheima.springbootwebquickstart.dao.impl.EmpDaoA;
import com.itheima.springbootwebquickstart.pojo.Emp;
import com.itheima.springbootwebquickstart.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

//@Component
@Service
public class EmpServiceA implements EmpService {
//    private EmpDao empDao=new EmpDaoA();
    //耦合性太强需要解耦

    @Autowired//运行时IOC容器会提供该类型的bean对象
    private EmpDao empDao;
    @Override
    public List<Emp> listEmp() {
        List<Emp> empList=empDao.listEmp();
        empList.stream().forEach(emp->{
            String gender=emp.getGender();
            if("1".equals(gender))
            {
                emp.setGender("男");
            } else if ("2".equals(gender)) {
                emp.setGender("女");
            }
            String job=emp.getJob();
            if("1".equals(job))
            {
                emp.setJob("讲师");
            } else if ("2".equals(job)) {
                emp.setJob("班主任");
            } else if ("3".equals(job)) {
                emp.setJob("就业指导");
            }
        });
        return empList;
    }
}

大概就是使用@Component让该类于容器管理,然后用@Autowired来向接口的别名分配

 

标签:03,springbootwebquickstart,06,equals,2024,emp,import,com,itheima
From: https://www.cnblogs.com/zhenaifen/p/18057808

相关文章

  • 20240302 专项训练
    背包专项训练bottle题意简述link有\(n\)瓶水,第\(i\)瓶水有剩余水量\(a_i\)和最大容积\(b_i\),在不超过瓶子容积的前提下,小A可以把任意多的水从一个瓶子倒向另一个瓶子,所花费的时间等同于倒过去的水的体积。求最多能得到多少个空瓶,以及在得到最多的空瓶的前提下,他最少......
  • The Marvels of an Electronic Technician's World
    Welcometothefascinatingworldofelectronictechnicians!Inthisblogpost,wewilldiveintotheexcitingrealmoftheseunsungheroeswhoworkbehindthescenestokeepourgadgetsrunningsmoothly.Fromtroubleshootingtorepairing,anelectronicte......
  • EGF 练习题(近期总结 2024.3.6)
    Luogu5401珍珠题意:有\(n\)个变量,取值范围均为\([1,D]\)中的整数。求有多少种取值方案,使得可以选出至少\(m\)对变量满足每对都相等。\(1\leD\le10^5,\space0\lem\len,\space1\len\le10^9\)注意到\(D\)很小,我们可以计算出个数为奇数的值最多\(n-2m\)个,偶数最......
  • Abbott的复仇 Abbott's Revenge
    原题链接bfs的深度用法。这题最坑的我觉得是输入输出格式的处理(一不小心就容易格式错误)调了好几个小时.....这里放一组udebug数据SAMPLE31N3311WLNR*12WLNRERWF*13NLER*21SLWRNF*22SLWFELF*23SFREL*0NOSOLUTION31N3211WLNR......
  • 2024.3.06
    今日跟着一个人进行了Androidstudio上创建数据库和数据表的联系,这应该是老师留的作业中,进行数据库的连接。原文链接:https://blog.csdn.net/fjh_xx/article/details/131404230一.前言二.SQLite数据库介绍1.什么是SQLite数据库2.特点3.SQLite操作API4.SQLite数据类型三.S......
  • MAC OS :ERROR: Failed to open file '\Users\futantan\Downloads\atguigudb.sql'
    在操作source\Users\futantan\Downloads\atguigudb.sql的时候出现ERROR: Failedtoopenfile'\Users\futantan\Downloads\atguigudb.sql',error:2 解决方案,在对应的路径下开启mysql udandandeMacBook-Pro:mysqlfutantan$mysql-uroot-pEnterpassword:Welcom......
  • dday06_homework_set
    点击查看代码#列举你了解的字典中的功能(字典独有)。#keys/values/items/get/update/pop#列举你了解的集合中的功能(集合独有)。#add/update/discard/intersection/union/difference/symmetric_difference#列举你了解的可以转换为"""字符串转数字数字转字符串列表转元......
  • vim-common (= 2:7.4.1689-3ubuntu1.5) 但是 2:8.1.0320-1ubuntu3 正要被安装
    安装失败提示(普通用户)~$sudoapt-getinstallvim…下列软件包有未满足的依赖关系:vim:依赖:vim-common(=2:7.4.1689-3ubuntu1.5)但是2:8.1.0320-1ubuntu3正要被安装依赖:libpython3.5(>=3.5.0~b1)但是它将不会被安装依赖:libtinfo5(>=6)但是它将不会被安装解......
  • 2024 省选游记
    目录序言回首\(\text{Day-INF}\)\(\text{Day0}\)\(\text{Day1}\)\(\text{Day2}\)结语序言转眼入坑\(\text{OI}\)已经第\(2\)个年头了,依稀记得是从\(2021\)年\(11\)月份学习\(\text{C++}\),当时其实并不知道\(\text{OI}\)这个东西,只是把他当......
  • ARC068 vp记录
    A.X:YetAnotherDieGame题意:一个\(6\)面骰子,对面的两个点数和为\(7\)。初始的时候任意的一个面朝上,接下来每一轮可以翻转骰子到相邻的一面,并获得此面的得分(那一面的点数即是得分),问至少要几轮才可以获得够\(x\)分。\(1\lex\le10^{15}\)直接在\(5,6\)之间翻来翻去......