本文共 3509 字,大约阅读时间需要 11 分钟。
主要解决的是在微服务的架构下简化配置(有快速配置)、前后端分离、快速开发
优点:
提供了快速启动入门
开箱即用、提供默认配置
内嵌容器化web项目
没有冗余代码生成和xml配置要求
访问
生成下载demo.zip
<mirrors>
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
必须要继承的parnet
进入本地库
for /r %i in (*.lastUpdated) do del %i
然后update
删掉 重新update
所有错误都解决后
Jar方式运行 首先得有这个jar包
先clean package 生成jar文件,然后再run main方法
把jre的路径换成jdk的
下载
或者在eclipse上自己安装插件 spring tools
在resources目录下新建banner.txt
英文
图片
把所有的配置全放在这个文件里,方便统一管理,maven也可以做到
server.port=90
server.servlet.context-path=/demo
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.yxxy.MyApp</mainClass>
</configuration>
</plugin>
</plugins>
</build>
https://blog.csdn.net/cw_hello1/article/details/79639448
RestController = @Controller+@ResponseBody
一个效果
@RestController
public class MyAppController {
@RequestMapping("/")
public Map<String, String> index() {
Map<String, String> map = new HashMap<>();
map.put("aaa", "bbb");
map.put("aaa", "bbb");
map.put("aaa", "bbb");
map.put("aaa", "bbb");
return map;
}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
@Controller
public class IndexController {
@RequestMapping("/")
public String index(ModelMap map) {
// 加入一个属性,用来在模板中读取
map.addAttribute("msg", "nihao~");
return模板文件的名称,对应src/main/resources/templates/index.html
return "index";
}
<h1 th:text="${msg}">hi!</h1>
@RequestMapping("/")
@RestController
public class UserRestfulController {
static Map<Long, User> users = Collections.synchronizedMap(new HashMap<Long,User>());
@RequestMapping(value="/User",method=RequestMethod.GET)
public List<User> getUserList(){
ArrayList<User> list = new ArrayList<>(users.values());
return list;
}
@RequestMapping(value="User",method=RequestMethod.POST)
public String addUser(@ModelAttribute User user) {
users.put(user.getId(), user);
return "addUser Success";
}
}
public class User {
private Long id;
private String loginName;
private String password;
private String nickName;
@Autowired
private UserService userSrv;
@RequestMapping(value="/User",method=RequestMethod.GET)
public List<User> getUserList(){
return userSrv.getUserList();
}
@RequestMapping(value="User",method=RequestMethod.POST)
public String addUser(@ModelAttribute User user) {
String msg = userSrv.addUser(user);
return msg;
}
@Service
public class UserService {
static Map<Long, User> users = Collections.synchronizedMap(new HashMap<Long,User>());
public List<User> getUserList() {
ArrayList<User> list = new ArrayList<>(users.values());
return list;
}
public String addUser(User user) {
users.put(user.getId(), user);
return "addUser Success";
}
}
<h1>User list</h1>
<table>
<tr>
<th>NAME</th>
<th>loginName</th>
<th>nickName</th>
</tr>
<tr th:each="user : ${list}">
<td th:text="${user.id}">id</td>
<td th:text="${user.loginName}">loginName</td>
<td th:text="${user.nickName}">nickName</td>
</tr>
</table>
<p>
<a href="../home.html" th:href="@{/}">Return to home</a>
</p>