springboot(三 单独将controller放一个包下)
2017-12-06 11:35
281 查看
springboot的入口
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Configuration;
@SpringBootApplication
public class DatasourcesApplication {
public static void main(String[] args) {
SpringApplication.run(DatasourcesApplication.class, args);
}
}
controller类
package com.example.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Hello {
//连一个数据库
@RequestMapping(value="/hello")
//@ResponseBody
public String data1(){
System.err.println("进入controller");
return "hello";
}
}
这里需要注意 这两个位置 contrller在入口包里或者包下,否则访问不了
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Configuration;
@SpringBootApplication
public class DatasourcesApplication {
public static void main(String[] args) {
SpringApplication.run(DatasourcesApplication.class, args);
}
}
controller类
package com.example.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class Hello {
//连一个数据库
@RequestMapping(value="/hello")
//@ResponseBody
public String data1(){
System.err.println("进入controller");
return "hello";
}
}
这里需要注意 这两个位置 contrller在入口包里或者包下,否则访问不了
相关文章推荐
- springboot demo写好之后再去写一个controller,怎么也访问不到页面
- spring boot结合dubbox一个坑爹的例子
- spring boot controller路由 url 扫描不到问题
- Spring Boot 构建一个RESTful Web服务
- spring boot 视图映射碰到的一个小坑
- Spring Boot + Spring Security 防止用户在多处同时登录(一个用户同时只能登录一次)及源码分析
- 使用Spring Security给Spring Boot Admin做一个安全验证登录
- springboot使用addViewController减少控制器代码的编写
- 一个简单的基于注解的 Controller (spring 2.5 annotation 方式实现mvc )
- SpringBoot之Controller(B)
- 快速搭建一个简单的springboot项目
- 【springBoot】springBoot返回json的一个问题
- spring boot demo( 获取一个RESTful web service)
- 用Kotlin写一个基于Spring Boot的RESTful服务
- Spring boot扫描不到controller注解
- 使用maven创建一个spring-boot项目-集成springmvc
- IntelliJ IDEA搭建SpringBoot应用完成的一个小Demo
- 创建一个springboot项目
- Spring Boot 微框架学习(利用Spring Boot编写一个访问数据库的helloword)
- spring boot学习(三)---Controller