spring,springmvc,springboot注解 in work

8 篇文章 0 订阅
3 篇文章 0 订阅
@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;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值