Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
first-boot
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
train
first-boot
Commits
c67c41d5
Commit
c67c41d5
authored
Nov 07, 2018
by
徐奇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
INIT
parent
a8083faf
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
351 additions
and
0 deletions
+351
-0
pom.xml
+21
-0
readme.md
+27
-0
src/main/java/cn/freemud/firstboot/FirstBootApplication.java
+2
-0
src/main/java/cn/freemud/firstboot/config/Swagger2Config.java
+43
-0
src/main/java/cn/freemud/firstboot/dao/ProductDao.java
+46
-0
src/main/java/cn/freemud/firstboot/service/ProductService.java
+19
-0
src/main/java/cn/freemud/firstboot/service/impl/DefaultProductService.java
+37
-0
src/main/java/cn/freemud/firstboot/vo/ProductCreateReq.java
+20
-0
src/main/java/cn/freemud/firstboot/vo/ProductResp.java
+24
-0
src/main/java/cn/freemud/firstboot/web/ProductController.java
+58
-0
src/main/java/cn/freemud/firstboot/web/ProductPageController.java
+41
-0
src/main/resources/application.properties
+1
-0
src/main/resources/templates/product.html
+12
-0
No files found.
pom.xml
View file @
c67c41d5
...
@@ -33,6 +33,10 @@
...
@@ -33,6 +33,10 @@
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
...
@@ -49,6 +53,23 @@
...
@@ -49,6 +53,23 @@
<artifactId>
spring-boot-starter-test
</artifactId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-thymeleaf
</artifactId>
</dependency>
<!-- Swagger -->
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger-ui
</artifactId>
<version>
2.9.2
</version>
</dependency>
<dependency>
<groupId>
io.springfox
</groupId>
<artifactId>
springfox-swagger2
</artifactId>
<version>
2.9.2
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
readme.md
0 → 100644
View file @
c67c41d5
# 第一个SpringBoot 应用
## bean定义
*
@RestController
*
@Controller
*
@Service
*
@Repository
*
@Component
## bean的注入
*
@Autowired
*
@Resource(name = "defaultProductService")
*
还有setter注入、构造函数注入,一般不使用
## swagger文档
*
增加pom
*
增加注释
*
增加配置
*
访问地址:http://localhost:8080/swagger-ui.html
## Spring MVC
*
thymeleaf
## lombok
*
idea 插件安装
src/main/java/cn/freemud/firstboot/FirstBootApplication.java
View file @
c67c41d5
...
@@ -2,7 +2,9 @@ package cn.freemud.firstboot;
...
@@ -2,7 +2,9 @@ package cn.freemud.firstboot;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@EnableSwagger2
@SpringBootApplication
@SpringBootApplication
public
class
FirstBootApplication
{
public
class
FirstBootApplication
{
...
...
src/main/java/cn/freemud/firstboot/config/Swagger2Config.java
0 → 100644
View file @
c67c41d5
/*
* Copyright (c) 2018 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
firstboot
.
config
;
import
com.google.common.base.Predicates
;
import
io.swagger.annotations.Api
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
springfox.documentation.builders.ApiInfoBuilder
;
import
springfox.documentation.builders.PathSelectors
;
import
springfox.documentation.builders.RequestHandlerSelectors
;
import
springfox.documentation.service.ApiInfo
;
import
springfox.documentation.spi.DocumentationType
;
import
springfox.documentation.spring.web.plugins.Docket
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@Configuration
@EnableSwagger2
//@Profile({"dev", "test"})
public
class
Swagger2Config
{
@Bean
public
Docket
createRestApi
()
{
return
new
Docket
(
DocumentationType
.
SWAGGER_2
)
.
apiInfo
(
apiInfo
())
.
select
()
.
apis
(
Predicates
.
and
(
RequestHandlerSelectors
.
basePackage
(
"cn.freemud"
),
RequestHandlerSelectors
.
withClassAnnotation
(
Api
.
class
)))
.
paths
(
PathSelectors
.
any
())
.
build
();
}
private
ApiInfo
apiInfo
()
{
return
new
ApiInfoBuilder
()
.
title
(
"API"
)
.
description
(
" APIs"
)
.
termsOfServiceUrl
(
"http://www.freemud.cn/"
)
.
version
(
"1.0"
)
.
build
();
}
}
src/main/java/cn/freemud/firstboot/dao/ProductDao.java
0 → 100644
View file @
c67c41d5
/*
* Copyright (c) 2018 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
firstboot
.
dao
;
import
cn.freemud.firstboot.vo.ProductCreateReq
;
import
cn.freemud.firstboot.vo.ProductResp
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Repository
;
/**
* @author qi.xu 2018/11/7 11:15
*/
@Slf4j
@Repository
public
class
ProductDao
{
private
static
final
String
PRODUCT_NAME
=
"产品名称"
;
private
static
final
String
NEWID
=
"NEWID"
;
/**
*
* @param id
* @return
*/
public
ProductResp
getById
(
String
id
)
{
ProductResp
productResp
=
new
ProductResp
();
productResp
.
setId
(
id
);
productResp
.
setProductName
(
id
+
PRODUCT_NAME
);
return
productResp
;
}
/**
*
* @param req
* @return
*/
public
ProductResp
create
(
ProductCreateReq
req
)
{
ProductResp
productResp
=
new
ProductResp
();
productResp
.
setId
(
NEWID
);
productResp
.
setProductName
(
req
.
getProductName
());
return
productResp
;
}
}
src/main/java/cn/freemud/firstboot/service/ProductService.java
0 → 100644
View file @
c67c41d5
/*
* Copyright (c) 2018 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
firstboot
.
service
;
import
cn.freemud.firstboot.vo.ProductCreateReq
;
import
cn.freemud.firstboot.vo.ProductResp
;
/**
* @author qi.xu 2018/11/7 11:15
*/
public
interface
ProductService
{
ProductResp
getById
(
String
id
);
ProductResp
create
(
ProductCreateReq
req
);
}
src/main/java/cn/freemud/firstboot/service/impl/DefaultProductService.java
0 → 100644
View file @
c67c41d5
/*
* Copyright (c) 2018 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
firstboot
.
service
.
impl
;
import
cn.freemud.firstboot.dao.ProductDao
;
import
cn.freemud.firstboot.service.ProductService
;
import
cn.freemud.firstboot.vo.ProductCreateReq
;
import
cn.freemud.firstboot.vo.ProductResp
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
/**
* @author qi.xu 2018/11/7 11:16
*/
@Service
@Slf4j
public
class
DefaultProductService
implements
ProductService
{
@Autowired
private
ProductDao
productDao
;
@Override
public
ProductResp
getById
(
String
id
)
{
log
.
info
(
"id = {}"
,
id
);
return
productDao
.
getById
(
id
);
}
@Override
public
ProductResp
create
(
ProductCreateReq
req
)
{
return
productDao
.
create
(
req
);
}
}
src/main/java/cn/freemud/firstboot/vo/ProductCreateReq.java
0 → 100644
View file @
c67c41d5
/*
* Copyright (c) 2018 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
firstboot
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* @author qi.xu 2018/11/7 11:18
*/
@Data
@ApiModel
(
description
=
"产品创建请求"
)
public
class
ProductCreateReq
{
@ApiModelProperty
(
value
=
"产品名称"
)
private
String
productName
;
}
src/main/java/cn/freemud/firstboot/vo/ProductResp.java
0 → 100644
View file @
c67c41d5
/*
* Copyright (c) 2018 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
firstboot
.
vo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* @author qi.xu 2018/11/7 11:18
*/
@Data
@ApiModel
(
description
=
"产品返回"
)
public
class
ProductResp
{
@ApiModelProperty
(
value
=
"产品ID"
)
private
String
id
;
@ApiModelProperty
(
value
=
"产品名称"
)
private
String
productName
;
}
src/main/java/cn/freemud/firstboot/web/ProductController.java
0 → 100644
View file @
c67c41d5
/*
* Copyright (c) 2018 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
firstboot
.
web
;
import
cn.freemud.firstboot.service.ProductService
;
import
cn.freemud.firstboot.vo.ProductCreateReq
;
import
cn.freemud.firstboot.vo.ProductResp
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
@Api
@RestController
@RequestMapping
(
"/product"
)
@Slf4j
public
class
ProductController
{
@Autowired
private
ProductService
productService
;
@Resource
(
name
=
"defaultProductService"
)
private
ProductService
defaultProductService
;
@ApiOperation
(
value
=
"根据ID获取产品"
,
notes
=
"根据ID获取产品"
)
@ApiImplicitParam
(
value
=
"请求"
,
required
=
true
,
dataType
=
"String"
,
name
=
"id"
)
@GetMapping
(
"/getById"
)
public
ProductResp
getById
(
String
id
)
{
return
productService
.
getById
(
id
);
}
@ApiOperation
(
value
=
"根据ID获取产品"
,
notes
=
"根据ID获取产品"
)
@ApiImplicitParam
(
value
=
"请求"
,
required
=
true
,
dataType
=
"String"
,
name
=
"id"
)
@RequestMapping
(
value
=
"/getById2"
,
method
=
RequestMethod
.
GET
)
public
ProductResp
getById2
(
@RequestParam
String
id
)
{
return
defaultProductService
.
getById
(
id
);
}
@ApiOperation
(
value
=
"创建产品"
,
notes
=
"创建产品"
)
@ApiImplicitParam
(
value
=
"请求"
,
required
=
true
,
dataType
=
"ProductCreateReq"
,
name
=
"req"
)
@RequestMapping
(
value
=
"/create"
,
method
=
RequestMethod
.
POST
)
public
ProductResp
create
(
@RequestBody
ProductCreateReq
req
)
{
return
productService
.
create
(
req
);
}
}
src/main/java/cn/freemud/firstboot/web/ProductPageController.java
0 → 100644
View file @
c67c41d5
/*
* Copyright (c) 2018 www.freemud.cn Inc. All rights reserved.
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目
*/
package
cn
.
freemud
.
firstboot
.
web
;
import
cn.freemud.firstboot.service.ProductService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
@Api
@Controller
@RequestMapping
(
"/page"
)
@Slf4j
public
class
ProductPageController
{
@Autowired
private
ProductService
productService
;
@Resource
(
name
=
"defaultProductService"
)
private
ProductService
defaultProductService
;
@ApiOperation
(
value
=
"创建产品"
,
notes
=
"创建产品"
)
@ApiImplicitParam
(
value
=
"请求"
,
required
=
true
,
dataType
=
"String"
,
name
=
"id"
)
@GetMapping
(
"/create"
)
public
String
kafkaTest
(
Model
model
,
String
id
)
{
model
.
addAttribute
(
"id"
,
id
);
return
"product"
;
}
}
src/main/resources/application.properties
View file @
c67c41d5
spring.application.name
=
first-spring-boot-service
src/main/resources/templates/product.html
0 → 100644
View file @
c67c41d5
<!DOCTYPE html>
<html
lang=
"en"
xmlns:th=
"http://www.w3.org/1999/xhtml"
>
<head>
<meta
charset=
"UTF-8"
/>
<title>
产品
</title>
</head>
<body>
<H1>
创建产品
</H1>
产品id:
<span
th:text=
"${id}"
>
ID
</span>
</body>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment