spring boot 分层demo(二)

1.添加依赖 springmvc 与 连接池


<dependency>
   <groupId>org.springframeworkgroupId>
   <artifactId>spring-webmvcartifactId>
   <version>4.3.7.RELEASEversion>
dependency>


<dependency>
   <groupId>com.jolboxgroupId>
   <artifactId>bonecp-springartifactId>
   <version>0.8.0.RELEASEversion>
dependency>
2.com.heimeiqiu.controller.TestHelloController

import com.heimeiqiu.entity.Hruser;
import com.heimeiqiu.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wxl on 2017/12/13.
 */
@RestController
@EnableAutoConfiguration
public class TestHelloController {

    @Autowired
    private TestService testService;

    @RequestMapping("/")
    @ResponseBody
    public String home() {
        return "Hello World!";
    }

    @RequestMapping("/ceshi")
    @ResponseBody
    public Hruser homeCeshi() {
        Hruser user = testService.getTestInfo();
        return user;
    }
}
2.com.heimeiqiu.service.TestService

package com.heimeiqiu.service;

import com.heimeiqiu.dao.TestDao;
import com.heimeiqiu.entity.Hruser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by wxl on 2017/12/13.
 */
@Service
public class TestService {
    @Autowired
    private TestDao testDao;

    public Hruser getTestInfo() {
        return testDao.selectTestInfo();
    }
}
3.com.heimeiqiu.dao.TestDao

package com.heimeiqiu.dao;

import com.heimeiqiu.entity.Hruser;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * Created by wxl on 2017/12/13.
 */
@Repository
public class TestDao {
    public Hruser selectTestInfo() {
        Hruser user = new Hruser();
        return user;
    }
}
4.com.heimeiqiu.entity.Hruser

package com.heimeiqiu.entity;

public class Hruser {
    private String id;

    private String userid;

    private String username;

    private String itcode;

    private String department;

    private String department_txt;

    private String comp_code;

    private String comp_code_txt;

    private String cpmo_cop;

    private String cpmo_cop_txt;

    private String xa_mreg;

    private String xa_mreg_txt;

    private String xa_reig;

    private String xa_reig_txt;

    private String xa_dept;

    private String xa_dept_txt;

    private String xa_grop;

    private String xa_grop_txt;

    public String getId() {
        return id;
    }

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

    public String getUserid() {
        return userid;
    }

    public void setUserid(String userid) {
        this.userid = userid;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getItcode() {
        return itcode;
    }

    public void setItcode(String itcode) {
        this.itcode = itcode;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getDepartment_txt() {
        return department_txt;
    }

    public void setDepartment_txt(String department_txt) {
        this.department_txt = department_txt;
    }

    public String getComp_code() {
        return comp_code;
    }

    public void setComp_code(String comp_code) {
        this.comp_code = comp_code;
    }

    public String getComp_code_txt() {
        return comp_code_txt;
    }

    public void setComp_code_txt(String comp_code_txt) {
        this.comp_code_txt = comp_code_txt;
    }

    public String getCpmo_cop() {
        return cpmo_cop;
    }

    public void setCpmo_cop(String cpmo_cop) {
        this.cpmo_cop = cpmo_cop;
    }

    public String getCpmo_cop_txt() {
        return cpmo_cop_txt;
    }

    public void setCpmo_cop_txt(String cpmo_cop_txt) {
        this.cpmo_cop_txt = cpmo_cop_txt;
    }

    public String getXa_mreg() {
        return xa_mreg;
    }

    public void setXa_mreg(String xa_mreg) {
        this.xa_mreg = xa_mreg;
    }

    public String getXa_mreg_txt() {
        return xa_mreg_txt;
    }

    public void setXa_mreg_txt(String xa_mreg_txt) {
        this.xa_mreg_txt = xa_mreg_txt;
    }

    public String getXa_reig() {
        return xa_reig;
    }

    public void setXa_reig(String xa_reig) {
        this.xa_reig = xa_reig;
    }

    public String getXa_reig_txt() {
        return xa_reig_txt;
    }

    public void setXa_reig_txt(String xa_reig_txt) {
        this.xa_reig_txt = xa_reig_txt;
    }

    public String getXa_dept() {
        return xa_dept;
    }

    public void setXa_dept(String xa_dept) {
        this.xa_dept = xa_dept;
    }

    public String getXa_dept_txt() {
        return xa_dept_txt;
    }

    public void setXa_dept_txt(String xa_dept_txt) {
        this.xa_dept_txt = xa_dept_txt;
    }

    public String getXa_grop() {
        return xa_grop;
    }

    public void setXa_grop(String xa_grop) {
        this.xa_grop = xa_grop;
    }

    public String getXa_grop_txt() {
        return xa_grop_txt;
    }

    public void setXa_grop_txt(String xa_grop_txt) {
        this.xa_grop_txt = xa_grop_txt;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Hruser other = (Hruser) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
            && (this.getUserid() == null ? other.getUserid() == null : this.getUserid().equals(other.getUserid()))
            && (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername()))
            && (this.getItcode() == null ? other.getItcode() == null : this.getItcode().equals(other.getItcode()))
            && (this.getDepartment() == null ? other.getDepartment() == null : this.getDepartment().equals(other.getDepartment()))
            && (this.getDepartment_txt() == null ? other.getDepartment_txt() == null : this.getDepartment_txt().equals(other.getDepartment_txt()))
            && (this.getComp_code() == null ? other.getComp_code() == null : this.getComp_code().equals(other.getComp_code()))
            && (this.getComp_code_txt() == null ? other.getComp_code_txt() == null : this.getComp_code_txt().equals(other.getComp_code_txt()))
            && (this.getCpmo_cop() == null ? other.getCpmo_cop() == null : this.getCpmo_cop().equals(other.getCpmo_cop()))
            && (this.getCpmo_cop_txt() == null ? other.getCpmo_cop_txt() == null : this.getCpmo_cop_txt().equals(other.getCpmo_cop_txt()))
            && (this.getXa_mreg() == null ? other.getXa_mreg() == null : this.getXa_mreg().equals(other.getXa_mreg()))
            && (this.getXa_mreg_txt() == null ? other.getXa_mreg_txt() == null : this.getXa_mreg_txt().equals(other.getXa_mreg_txt()))
            && (this.getXa_reig() == null ? other.getXa_reig() == null : this.getXa_reig().equals(other.getXa_reig()))
            && (this.getXa_reig_txt() == null ? other.getXa_reig_txt() == null : this.getXa_reig_txt().equals(other.getXa_reig_txt()))
            && (this.getXa_dept() == null ? other.getXa_dept() == null : this.getXa_dept().equals(other.getXa_dept()))
            && (this.getXa_dept_txt() == null ? other.getXa_dept_txt() == null : this.getXa_dept_txt().equals(other.getXa_dept_txt()))
            && (this.getXa_grop() == null ? other.getXa_grop() == null : this.getXa_grop().equals(other.getXa_grop()))
            && (this.getXa_grop_txt() == null ? other.getXa_grop_txt() == null : this.getXa_grop_txt().equals(other.getXa_grop_txt()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getUserid() == null) ? 0 : getUserid().hashCode());
        result = prime * result + ((getUsername() == null) ? 0 : getUsername().hashCode());
        result = prime * result + ((getItcode() == null) ? 0 : getItcode().hashCode());
        result = prime * result + ((getDepartment() == null) ? 0 : getDepartment().hashCode());
        result = prime * result + ((getDepartment_txt() == null) ? 0 : getDepartment_txt().hashCode());
        result = prime * result + ((getComp_code() == null) ? 0 : getComp_code().hashCode());
        result = prime * result + ((getComp_code_txt() == null) ? 0 : getComp_code_txt().hashCode());
        result = prime * result + ((getCpmo_cop() == null) ? 0 : getCpmo_cop().hashCode());
        result = prime * result + ((getCpmo_cop_txt() == null) ? 0 : getCpmo_cop_txt().hashCode());
        result = prime * result + ((getXa_mreg() == null) ? 0 : getXa_mreg().hashCode());
        result = prime * result + ((getXa_mreg_txt() == null) ? 0 : getXa_mreg_txt().hashCode());
        result = prime * result + ((getXa_reig() == null) ? 0 : getXa_reig().hashCode());
        result = prime * result + ((getXa_reig_txt() == null) ? 0 : getXa_reig_txt().hashCode());
        result = prime * result + ((getXa_dept() == null) ? 0 : getXa_dept().hashCode());
        result = prime * result + ((getXa_dept_txt() == null) ? 0 : getXa_dept_txt().hashCode());
        result = prime * result + ((getXa_grop() == null) ? 0 : getXa_grop().hashCode());
        result = prime * result + ((getXa_grop_txt() == null) ? 0 : getXa_grop_txt().hashCode());
        return result;
    }
}
5.启动类添加扫描

package com.heimeiqiu;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = "com.heimeiqiu")
public class HmqDemoServerApplication {

   public static void main(String[] args) {
      SpringApplication.run(HmqDemoServerApplication.class, args);
   }
}

你可能感兴趣的:(spring,boot)