1:使用idea创建一个maven工程 bos2
2:删除bos2的src 文件夹,向pom.xml文件 中添加版本号
<packaging>pom</packaging>
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.li</groupId> <artifactId>bos2</artifactId> <version>1.0-SNAPSHOT</version> <modules> <module>crm_domain</module> <module>crm_management</module> </modules> <packaging>pom</packaging> <name>bos2.0</name> <description>bos v2.0综合平台</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> <relativePath/> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-data-jpa.version>1.9.0.RELEASE</spring-data-jpa.version> <elasticsearch.version>2.4.6</elasticsearch.version> <jackson.version>2.8.5</jackson.version> <boot-starter-jaxrs.version>3.2.0</boot-starter-jaxrs.version> <jna.version>3.0.9</jna.version> <ojdbc6.version>11.2.0.1.0</ojdbc6.version> <shiro.version>1.4.0</shiro.version> <pinyin4j.version>2.5.0</pinyin4j.version> <poi.version>3.11</poi.version> <httpclient.version>4.5.3</httpclient.version> <fastjson.version>1.2.8</fastjson.version> <mail.version>1.4.7</mail.version> <commons-lang.version>2.6</commons-lang.version> <commons-io.version>1.3.2</commons-io.version> <itext.version>5.2.0</itext.version> <quartz.version>2.2.1</quartz.version> <mysql.version>5.1.35</mysql.version> </properties> </project>
2:根目录右键 添加模块,选择maven工程。创建maven子模块 crm_domain
子模块pom.xml添加
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>bos2</artifactId> <groupId>com.li</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>crm_domain</artifactId> <name>crm_domain</name> <description>客户关系系统实体类</description> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <optional>true</optional> </dependency> </dependencies> </project>
3:创建对象
package top.kylewang.crm.domain; import javax.persistence.*; import javax.xml.bind.annotation.XmlRootElement; import java.util.Date; /** * @description:客户信息表 * */ @Entity @Table(name = "T_CUSTOMER") @XmlRootElement(name = "customer") public class Customer { @Id @GeneratedValue() @Column(name = "C_ID") private Integer id; // 主键id @Column(name = "C_USERNAME") private String username; // 用户名 @Column(name = "C_PASSWORD") private String password; // 密码 @Column(name = "C_TYPE") private Integer type; // 类型 设置1 绑定邮箱 @Column(name = "C_BRITHDAY") @Temporal(TemporalType.DATE) private Date birthday; // 生日 @Column(name = "C_SEX") private Integer sex; // 性别 1男 2女 @Column(name = "C_TELEPHONE") private String telephone; // 手机 @Column(name = "C_COMPANY") private String company; // 公司 @Column(name = "C_DEPARTMENT") private String department; // 部门 @Column(name = "C_POSITION") private String position; // 职位 @Column(name = "C_ADDRESS") private String address; // 地址 @Column(name = "C_MOBILEPHONE") private String mobilePhone; // 座机 @Column(name = "C_EMAIL") private String email; // 邮箱 @Column(name = "C_Fixed_AREA_ID") private String fixedAreaId; // 定区编码 public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Integer getType() { return type; } public void setType(Integer type) { this.type = type; } public Date getBirthday() { return birthday; } public void setBirthday(Date birthday) { this.birthday = birthday; } public Integer getSex() { return sex; } public void setSex(Integer sex) { this.sex = sex; } public String getTelephone() { return telephone; } public void setTelephone(String telephone) { this.telephone = telephone; } public String getCompany() { return company; } public void setCompany(String company) { this.company = company; } public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; } public String getPosition() { return position; } public void setPosition(String position) { this.position = position; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getMobilePhone() { return mobilePhone; } public void setMobilePhone(String mobilePhone) { this.mobilePhone = mobilePhone; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getFixedAreaId() { return fixedAreaId; } public void setFixedAreaId(String fixedAreaId) { this.fixedAreaId = fixedAreaId; } @Override public String toString() { return "Customer [id=" + id + ", username=" + username + ", password=" + password + ", type=" + type + ", birthday=" + birthday + ", sex=" + sex + ", telephone=" + telephone + ", company=" + company + ", department=" + department + ", position=" + position + ", address=" + address + ", mobilePhone=" + mobilePhone + ", email=" + email + ", fixedAreaId=" + fixedAreaId + "]"; } }
3:右键根工程创建一个子模块crm_management,使其依赖 crm_domain.向pom.xml中添加
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>bos2</artifactId> <groupId>com.li</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>crm_management</artifactId> <packaging>jar</packaging> <name>crm_management</name> <description>客户关系管理系统</description> <dependencies> <dependency> <groupId>com.li</groupId> <artifactId>crm_domain</artifactId> <version>1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxrs</artifactId> <version>${boot-starter-jaxrs.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!--jaxrs转json工具--> <dependency> <groupId>com.fasterxml.jackson.jaxrs</groupId> <artifactId>jackson-jaxrs-json-provider</artifactId> <version>${jackson.version}</version> </dependency> <!--commons工具包--> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-io</artifactId> <version>${commons-io.version}</version> </dependency> <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>${commons-lang.version}</version> </dependency> <!-- MySQL --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
5:在resources目录下添加application.yml,对子模块进行配置
server:
port: 9002 #配置设置服务的端口号
context-path: /crm #路径
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/crm
username: root
password: 136735
jpa:
show-sql: true #jpa
jackson:
default-property-inclusion: non_null
devtools:
restart:
enabled: true
cxf:
path: /services
servlet.init:
service-list-path: /info
jaxrs:
component-scan: true
6:创建controller和applicationMain主函数等
package top.kylewang.crm; import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; /** * @author Kyle.Wang * 2018/1/15 0015 11:59 */ @SpringBootApplication public class CrmManagementApplication { public static void main(String[] args) { SpringApplication.run(CrmManagementApplication.class, args); } @Bean public JacksonJaxbJsonProvider jacksonJaxbJsonProvider() { return new JacksonJaxbJsonProvider(); } }
package top.kylewang.crm.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; @RestController public class Test { @RequestMapping("hello") @ResponseBody public String getString(){ return"hello"; } }
7:运行springboot主函数, 访问 http://localhost:9002/crm/hello
结果为hello.
系统结构图