@RestController @RequestMapping("/ChargingSupply") public class ChargingSupplyController {
@RequestMapping(value = "/getHouseholdChargingRisk", method = { RequestMethod.POST, RequestMethod.GET }) public RestResponse getHouseholdChargingRisk(@RequestParam("level")int level,@RequestParam("guid")String guid, @RequestParam(value = "gridSize",required = false)Integer gridSize, @RequestParam(value = "gridPage",required = false)Integer gridPage){ return RestResponse.ok(areaChargingService.getRegionalRiskLevels(level,guid,gridSize,gridPage)); }
public Object sheducleDealBuildingRiskLevel(@RequestBody OrderVo orderVo){ return RestResponse.ok(orderCompanyService.addTransOrder(orderVo)); }
//body 传 list
public class OrderCarrierDto { private List<OrderCarrier> orderCarrierList; }
{
"orderCarrierList": [
{
"orderCompanyProductId": 1,
"companyId": 1,
"orderCarrierWeigth": "7"
},
{
"orderCompanyProductId": 2,
"companyId": 2,
"orderCarrierWeigth": "3"
}
]
}或者 public RestResponse editComapnyProfile(BafcEnterpriseInfo bafcEnterpriseInfo) 这样直接在param中传,而不需在body中传
@GetMapping
@PostMapping
spring相关注解:
创建对象存储在spring容器中
@controller @service @Component
注入spring容器中的对象
@Autowired:自动根据类型注入 @Qualifier(“名称”):指定自动注入的id名称 @Resource @Bean
@EnableScheduling @EnableAspectJAutoProxy //@EnableCaching @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) @ComponentScan(basePackages = {"com.sf"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = com.sf.gis.app.framework.Scheduled.QuartzConfig.class)) @ImportResource({"classpath:application-context.xml"}) @SpringBootApplication(exclude={DataSourceAutoConfiguration.class}) @EnableTransactionManagement public class HcfiregovernApp extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(HcfiregovernApp.class, args); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(HcfiregovernApp.class); } }
Mapper相关
@MapperScan 配置一个或多个路径,自动扫描这些包路径下的类,自动生成代理类
定时任务
@EnableScheduing --- 定义在class上
@Schedule(corn = 秒分时日月周) --- 定义方法上
异步任务:
@EnableAsync 类上
@Async 方法上;开启一个线程 ; 先执行没有@Async注解的方法,再执行有@Async注解的方法
@ImportResource 用于将自定义的 applicationContext.xml文件中的bean加载到Application Context中。
@ImportResource({"classpath:application-context.xml"})
@ComponentScan 根据定义的扫描路径,把符合扫描规则的类装配到spring容器中
@ComponentScan(basePackages = {"com.sf"})
@configureProperties 获取配置文件给对象注入
@ConfigurationProperties(prefix = "spring.lock.redisson") public class RedissonProperties { @Value("${spring.lock.redisson.timeout:${spring.redis.timeout:3000}}") private int timeout;
@PropetySource 注入properties配置文件
@Component @PropertySource(value = {"classpath:people.properties"},ignoreResourceNotFound = false,encoding = "UTF-8",name = "people.properties") public class PeopleProperties { @Value("${female.name}") private String name;