《十次方》07、搭建基础工程以及标签的CRUD
2019-01-05 本文已影响40人
db41bbeed50c
1、模块搭建
(1)、搭建基础微服务模块tensquare_base , pom.xml引入依赖
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.tensquare</groupId>
<artifactId>tensquare_common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
(2)、创建启动类
@SpringBootApplication
public class BaseApplication {
public static void main(String[] args) {
SpringApplication.run(BaseApplication.class, args);
}
@Bean
public IdWorker createIdWorker() {
return new IdWorker(1, 1);
}
}
(3)、在resources下创建application.y
server:
port: 9001
spring:
application:
name: tensquare-base #给微服务起名,使用中划线
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.17.128:3306/tensquare_base?characterEncoding=UTF-8
username: root
password: 123456
jpa:
database: mysql
show-sql: true
2、添加标签
实体类
public class Label implements Serializable{
@Id
private String id;//
private String labelname;//标签名称
private String state;//状态
private Long count;//使用数量
private Long fans;//关注数
private String recommend;//是否推荐
控制层
//根据id查询
@RequestMapping(value = "{id}", method = RequestMethod.GET)
public Result findById(@PathVariable String id) {
Label label = labelService.findById(id);
return new Result(true, StatusCode.OK, "查询成功", label);
}
业务层
public Label findById(String id) {
return labelDao.findById(id).get();
}
持久层
public interface LabelDao extends JpaRepository<Label, String>,
JpaSpecificationExecutor<Label> {
}
这里就和大家写一个查询吧!其他的看大家的了。