没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
1. 加载配置文件
2.
com.didispace.blog.name=程序猿 DD
com.didispace.blog.title=Spring Boot 教程
com.didispace.blog.desc=${com.didispace.blog.name}正在努力写《${com.didispace.blog.title}》
# 随机字符串
com.didispace.blog.value=${random.value}
# 随机 int
com.didispace.blog.number=${random.int}
# 随机 long
com.didispace.blog.bignumber=${random.long}
# 10 以内的随机数
com.didispace.blog.test1=${random.int(10)}
# 10-20 的随机数
com.didispace.blog.test2=${random.int[10,20]}
# 多环境配置文件激活属性
spring.profiles.active=dev //开发模式还是别的模式
3.
配置文件设置
Controller 书写格式
@RequestMapping(value="/", method=RequestMethod.POST)
public String postUser(@ModelAttribute User user) {
// 处理"/users/"的 POST 请求,用来创建 User
// 除了@ModelAttribute 绑定参数之外,还可以通过@RequestParam 从页面中传递参数
users.put(user.getId(), user);
return "success";
}
@RequestMapping(value="/{id}", method=RequestMethod.GET)
public User getUser(@PathVariable Long id) {
// 处理"/users/{id}"的 GET 请求,用来获取 url 中 id 值的 User 信息
// url 中的 id 可通过@PathVariable 绑定到函数的参数中
return users.get(id);
}
用 templeate 模板时需要添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
Controller 书写格式有一个 model 域可以添加一些信息
@Controller
public class HelloController {
@ResponseBody
@RequestMapping("/hello")
public String hello() {
return "Hello World";
}
@RequestMapping("/")
public String index(ModelMap map) {
map.addAttribute("host", "http://blog.didispace.com");
return "index";
}
}
添加 freemarker
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
界面展示
Velocity 模板
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-velocity</artifactId>
</dependency>
展示界面
swagger 模板
Swagger 配置信息
@Configuration
@EnableSwagger2
public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.didispace.web")) //这个是扫描的
controller
.paths(PathSelectors.any())
.build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("Spring Boot 中使用 Swagger2 构建 RESTful APIs")
.description("更多 Spring Boot 相关文章请关注:http://blog.didispace.com/")
.termsOfServiceUrl("http://blog.didispace.com/")
.contact("程序猿 DD")
.version("1.0")
.build();
}
}
剩余43页未读,继续阅读
资源评论
- yanyundi2018-05-03不错, 刚好用到
- Suc12018-05-05不是很好啊
默从.
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功