idea项目注意事项(bean controller dao service)

idea项目注意事项(bean controller dao service),第1张

idea项目注意事项(bean controller dao service)
代码进行分类开发,会提高我们开发效率和排错效率
 通常情况下,常见会4层:
 bean: 一般存放的是将来要new的实体类
 controller: 一般是数据的入口类
 dao: 具体对数据做 *** 作的地方,放在dao层,这一层一般情况下,都是对数据库做 *** 作的。
 service: 一般在这里面放的是接口,和实现类。

下面是一个举例:

//bean目录下的实体类
public class BasketballCoachMan extends CoachMan{
    public BasketballCoachMan() {
    }

    public BasketballCoachMan(String name, int age) {
        super(name, age);
    }
}
public class BasketballMan extends SportMan{
    public BasketballMan() {
    }

    public BasketballMan(String name, int age) {
        super(name, age);
    }
}
public abstract class CoachMan extends Person{
    public CoachMan() {
    }

    public CoachMan(String name, int age) {
        super(name, age);
    }
}
public abstract class Person {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

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

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void show() {
        System.out.println("姓名:" + name + ",年龄:" + age);
    }
}
public abstract class SportMan extends Person{
    public SportMan() {
    }

    public SportMan(String name, int age) {
        super(name, age);
    }
}
controller用来存放main方法是项目运行的入口
//测试类,测试写的案例
public class SportManDemo {
    public static void main(String[] args) {
        //创建一个乒乓球运动员对象
        SportMan sm = new PingPangSportManImpl("小王",18);
        sm.show();
        ((PingPangSportManImpl)sm).studyEnglish();

        //创建一个篮球运动员
        SportMan sm2 = new BasketballMan("小李",19);
        sm2.show();
//        ((BasketballMan)sm2).studyEnglish();

    }
}
 service: 一般在这里面放的是接口,和实现类。
public interface PingPang {
    public abstract void studyEnglish();
}
public class PingPangCoachManImpl extends CoachMan implements PingPang {
    public PingPangCoachManImpl() {
    }

    public PingPangCoachManImpl(String name, int age) {
        super(name, age);
    }

    @Override
    public void studyEnglish() {
        System.out.println("乒乓球教练学习英语");
    }
}
public class PingPangSportManImpl extends SportMan implements PingPang {

    public PingPangSportManImpl() {
    }

    public PingPangSportManImpl(String name, int age) {
        super(name, age);
    }

    @Override
    public void studyEnglish() {
        System.out.println("乒乓球运动员学习英语");
    }
}
至于Dao类主要存放数据库的

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5706997.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存