@Target(value=TYPE) @Retention(value=RUNTIME) @Documented @Controller @ResponseBody public @interface RestController @Target(value=TYPE) @Retention(value=RUNTIME) @Documented @Controller @ResponseBody public @interface RestController
<pre name="code" class="java">import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.autoconfigure.jdbc.*;
import org.springframework.context.annotation.*;
@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration {
}
<pre name="code" class="java">import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.autoconfigure.jdbc.*;
import org.springframework.context.annotation.*;
@Configuration
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
public class MyConfiguration {
}
@Configuration
@ComponentScan(basePackages = "com.hyxt",includeFilters = {@ComponentScan.Filter(Aspect.class)})
@ComponentScan(basePackages = "com.hyxt",includeFilters = {@ComponentScan.Filter(Aspect.class)})
@SpringBootApplication
package com.example.myproject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
package com.example.myproject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication // same as @Configuration @EnableAutoConfiguration @ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@Component
@ConfigurationProperties(prefix="connection")
public class ConnectionSettings {
@NotNull
private InetAddress remoteAddress;
// ... getters and setters
}
@Component
@ConfigurationProperties(prefix="connection")
public class ConnectionSettings {
@NotNull
private InetAddress remoteAddress;
// ... getters and setters
}
@Profiles
Spring Profiles提供了一种隔离应用程序配置的方式,并让这些配置只能在特定的环境下生效。任何@Component或@Configuration都能被@Profile标记,从而限制加载它的时机。
[java] view plain copy print?在CODE上查看代码片派生到我的代码片
@Configuration
@Profile("production")
public class ProductionConfiguration {
// ...
}
@Configuration
@Profile("production")
public class ProductionConfiguration {
// ...
}@ResponseBody
@RequestParam String a =request.getParameter("a")。
@RequestParam String a =request.getParameter("a")。
RequestMapping("user/get/mac/{macAddress}")
public String getByMacAddress(@PathVariable String macAddress){
//do something;
}
RequestMapping("user/get/mac/{macAddress}")
public String getByMacAddress(@PathVariable String macAddress){
//do something;
}
/**
* 用户进行评论及对评论进行管理的 Controller 类;
*/
@Controller
@RequestMapping("/msgCenter")
public class MyCommentController extends BaseController {
@Autowired
CommentService commentService;
@Autowired
OperatorService operatorService;
/**
* 添加活动评论;
*
* @param applyId 活动 ID;
* @param content 评论内容;
* @return
*/
@ResponseBody
@RequestMapping("/addComment")
public Map<String, Object> addComment(@RequestParam("applyId") Integer applyId, @RequestParam("content") String content) {
....
return result;
}
}
/**
* 用户进行评论及对评论进行管理的 Controller 类;
*/
@Controller
@RequestMapping("/msgCenter")
public class MyCommentController extends BaseController {
@Autowired
CommentService commentService;
@Autowired
OperatorService operatorService;
/**
* 添加活动评论;
*
* @param applyId 活动 ID;
* @param content 评论内容;
* @return
*/
@ResponseBody
@RequestMapping("/addComment")
public Map<String, Object> addComment(@RequestParam("applyId") Integer applyId, @RequestParam("content") String content) {
....
return result;
}
}
@RequestMapping("/list/{applyId}")
public String list(@PathVariable Long applyId, HttpServletRequest request, ModelMap modelMap) {
}
@RequestMapping("/list/{applyId}")
public String list(@PathVariable Long applyId, HttpServletRequest request, ModelMap modelMap) {
}
/**
* 全局异常处理
*/
@ControllerAdvice
class GlobalDefaultExceptionHandler {
public static final String DEFAULT_ERROR_VIEW = "error";
@ExceptionHandler({TypeMismatchException.class,NumberFormatException.class})
public ModelAndView formatErrorHandler(HttpServletRequest req, Exception e) throws Exception {
ModelAndView mav = new ModelAndView();
mav.addObject("error","参数类型错误");
mav.addObject("exception", e);
mav.addObject("url", RequestUtils.getCompleteRequestUrl(req));
mav.addObject("timestamp", new Date());
mav.setViewName(DEFAULT_ERROR_VIEW);
return mav;
}}
/**
* 全局异常处理
*/
@ControllerAdvice
class GlobalDefaultExceptionHandler {
public static final String DEFAULT_ERROR_VIEW = "error";
@ExceptionHandler({TypeMismatchException.class,NumberFormatException.class})
public ModelAndView formatErrorHandler(HttpServletRequest req, Exception e) throws Exception {
ModelAndView mav = new ModelAndView();
mav.addObject("error","参数类型错误");
mav.addObject("exception", e);
mav.addObject("url", RequestUtils.getCompleteRequestUrl(req));
mav.addObject("timestamp", new Date());
mav.setViewName(DEFAULT_ERROR_VIEW);
return mav;
}}
# face++ key
face_api_key = R9Z3Vxc7ZcxfewgVrjOyrvu1d-qR****
face_api_secret =D9WUQGCYLvOCIdsbX35uTH********
# face++ key
face_api_key = R9Z3Vxc7ZcxfewgVrjOyrvu1d-qR****
face_api_secret =D9WUQGCYLvOCIdsbX35uTH********
@Value("${face_api_key}")
private String API_KEY;
@Value("${face_api_secret}")
private String API_SECRET;
@Value("${face_api_key}")
private String API_KEY;
@Value("${face_api_secret}")
private String API_SECRET;所以一般常用的配置都是配置在application.properties文件的
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有