您的位置:首页 > 编程语言 > Java开发

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在入口包里或者包下,否则访问不了

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  springboot