标签:muse 也会 common 建议 影响 ice tap 界面 上下文
ApplicationContext context = new AnnotationConfigApplicationContext(TestConfiguration.class);
如果加载spring-context.xml文件:
ApplicationContext context = new ClassPathXmlApplicationContext("spring-context.xml");
List<Map> getTimeLineColumn(@Param("cbIds") List<String> cbIds)throws Exception;
xml中示例:
<select id="getTimeLineColumn" resultType="Map">
select cu.USERNAME,cu.ID
from CASEBANK cb
join CASEUSER cu on cb.CUID=cu.id
WHERE cb.ID in
<foreach collection="cbIds" item="cbid" open="(" separator="," close=")">
#{cbid}
</foreach>
GROUP BY cu.ID,cu.USERNAME
ORDER BY id
</select>
@RestController
public class HelloController {
@RequestMapping(value="/hello/{id}",method= RequestMethod.GET)
public String sayHello(@PathVariable("id") Integer id){
return "id:"+id;
}
}
@RestController
public class HelloController {
@RequestMapping(value="/hello",method= RequestMethod.GET)
public String sayHello(@RequestParam("id") Integer id){
return "id:"+id;
}
}
@PostMapping(value = ConstScheduleUrl.COMMON_ADDACCESSORYLIST)
public ResponseResult addAccessoryList(@RequestParam("workPlanId") String workPlanId,@RequestBody ScheduleCommonWorkPlanVO commonWorkPlanVO){
commonWorkPlanCodeService.commonHandleAccessory(commonWorkPlanVO,workPlanId);
return ResponseResult.success();
}
//将缓存保存进andCache,并使用参数中的userId加上一个字符串(这里使用方法名称)作为缓存的key
@Cacheable(value="andCache",key="#userId + ‘findById‘")
public SystemUser findById(String userId) {
SystemUser user = (SystemUser) dao.findById(SystemUser.class, userId);
return user ;
}
//将缓存保存进andCache,并当参数userId的长度小于32时才保存进缓存,默认使用参数值及类型作为缓存的key
@Cacheable(value="andCache",condition="#userId.length < 32")
public boolean isReserved(String userId) {
System.out.println("hello andCache"+userId);
return false;
}
//定义该类中的所有缓存在CACHE_SYS_PAPER 里
@Service
@CacheConfig(cacheNames = { CacheConstants.CACHE_SYS_PAPER })
public class ScheduleTrainPaperService {
...
}
//SpEL方式定义key
CacheConstants.CACHE_ROOT_METHOD_NAME_ID="#root.methodName + #id"
@Cacheable(key = CacheConstants.CACHE_ROOT_METHOD_NAME_ID ,sync =true)
public ScheduleTrainOption get(Integer id) {
return trainOptionMapper.get(id);
}
@SpringBootApplication
@MapperScan("com.lz.water.monitor.mapper")
//也可以同时扫描多个包
@SpringBootApplication
@MapperScan({"com.kfit.demo","com.kfit.user"})
//如果mapper类没有在Spring Boot主程序可以扫描的包或者子包下面,可以使用如下方式进行配置
@SpringBootApplication
@MapperScan({"com.kfit.*.mapper","org.kfit.*.mapper"})
@Component
@ConfigurationProperties(prefix = "com.example.demo")
通过@Bean的方式进行声明,这里我们加在启动类即可,代码如下
@Bean
@ConfigurationProperties(prefix = "com.example.demo")
prefix 全部要改成小写,不可以配合@value 使用会报错
java.lang.IllegalArgumentException: Could not resolve placeholder ‘defaultPoints‘ in value "${defaultPoints}"
@PropertySource("classpath:jdbc.properties")
@Value(${jdbc.driver})
private String driver;
也可以配合@ConfigurationProperties 使用
@RestControllerAdvice
public class RmcpExceptionHandler {
private final static Logger logger = LoggerFactory.getLogger(RmcpExceptionHandler.class);
@ExceptionHandler(value = Exception.class)
@ResponseBody
public ResponseResult handle(Exception e) {
ResponseResult result = new ResponseResult();
if (e instanceof RmcpException) {
// 系统自定义异常
....
} else if (e instanceof ConstraintViolationException) {
....
} else if (e instanceof MethodArgumentTypeMismatchException) {
...
} else if (e instanceof MethodArgumentNotValidException){
...
}
else if (e instanceof HttpMessageNotReadableException) {
...
} else {
// 未知异常
...
}
e.printStackTrace();
return result;
}
}
@Bean
@ConditionalOnMissingBean(name = "imageValidateCodeGenerator")
public ValidateCodeGenerator imageValidateCodeGenerator() {
ImageCodeGenerator codeGenerator = new ImageCodeGenerator();
codeGenerator.setSecurityProperty(securityProperties);
return codeGenerator;
}
测试发现, @ConditionOnMissingBean 只能在@Bean 注释的方法上使用,不能再@Component 注释的类上使用
PROPAGATION_REQUIRES_NEW和PROPAGATION_NESTED的区别
REQUIRES_NEW:启动一个新的,不依赖环境的“内部”事务,这个事务将被完全commited或rolled back 而不依赖于外部事务,它拥有自己的隔离范围,自己的锁等等,当内部事务开始执行时,外部事务将被挂起,内部事务结束时,外部事务将继续执行。
NESTED:如果外部事务commit,嵌套事务也会被commit;如果外部事务roll back,嵌套事务也会被 roll back。
开始一个嵌套的事务,它是已经存在事务的一个真正的子事务,嵌套事务开始执行时,它将取得一个savepoint,如果这个嵌套事务失败,我们将回滚到此savepoint,嵌套事务是外部事务的一部分,只有外部事务结束后它才会被提交
标签:muse 也会 common 建议 影响 ice tap 界面 上下文
原文地址:https://www.cnblogs.com/lazyfox/p/14229863.html