boot框架下载地址
写代码前对boot框架进行准备工作:
1.如果是aliyun的要在pom.xml中修改版本
2.两者都要构建到maven中
正文:在创建两个本地网页,通过url文件名访问
文件1:boot/BootboostApplication
职能:提供main方法,服务器启动的入口
package boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class BootboostApplication {
public static void main(String[] args) {
SpringApplication.run(BootboostApplication.class, args);
}
}
文件2:boot/Test1
职能:创建、构筑网页内容,内部含有控制器class
package boot;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller//注解
public class Test1 { //控制器类
@RequestMapping("/hello") //控制了url路径和方法的对应关系 url:localhost:8080/hello
@ResponseBody
String hi() {
return "Hello, world";
}
@RequestMapping("/bye") //url:localhost:8080/bye
@ResponseBody
String bye() {
return "bye bye";
}
}