lord-of-code / loc-framework Goto Github PK
View Code? Open in Web Editor NEW本项目是完全基于Spring Boot2和Springcloud Finchley所进行了开发的,目的是简化和统一公司内部使用微服务框架的使用方法
License: MIT License
本项目是完全基于Spring Boot2和Springcloud Finchley所进行了开发的,目的是简化和统一公司内部使用微服务框架的使用方法
License: MIT License
`@Configuration
@ConditionalOnWebApplication(type = Type.SERVLET)
@EnableConfigurationProperties(LocSpringMvcCorsProperties.class)
public class LocSpringMvcAutoConfiguration {
@bean
@ConditionalOnClass(CorsFilter.class)
@ConditionalOnProperty(value = "loc.web.springmvc.cors.enabled")
public Filter corsFilter(LocSpringMvcCorsProperties locSpringMvcCorsProperties) {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration(
Optional.ofNullable(locSpringMvcCorsProperties.getPath()).orElse("/**"),
buildConfig(locSpringMvcCorsProperties));
return new CorsFilter(source);
}
private CorsConfiguration buildConfig(LocSpringMvcCorsProperties locSpringMvcCorsProperties) {
CorsConfiguration corsConfiguration = new CorsConfiguration();
Optional.ofNullable(locSpringMvcCorsProperties.getAllowOrigins())
.ifPresent(origins -> origins.forEach(corsConfiguration::addAllowedOrigin));
Optional.ofNullable(locSpringMvcCorsProperties.getAllowHeaders())
.ifPresent(headers -> headers.forEach(corsConfiguration::addAllowedHeader));
Optional.ofNullable(locSpringMvcCorsProperties.getAllowOrigins())
.ifPresent(methods -> methods.forEach(corsConfiguration::addAllowedMethod));
Optional.ofNullable(locSpringMvcCorsProperties.getAllowExposeHeaders())
.ifPresent(headers -> headers.forEach(corsConfiguration::addExposedHeader));
return corsConfiguration;
}`
两次使用了locSpringMvcCorsProperties.getAllowOrigins(),最后一次应该是locSpringMvcCorsProperties.getAllowMethods()
问题1:class和interface封装工具类除了代码默认简写外还有其他区别吗?因为interface没有private,所以还是喜欢用class写。
问题2:前后端分离后,数据用map封装放data好还是这样自定义好?
public class ProblemUtil {
public static Problem createProblem(Object... datas) {
ProblemBuilder builder = Problem.builder().withDetail("success").with("code", 0);
for(Object obj:datas){
String name = getName(obj);
builder.with(name,obj);
}
return builder.build();
}
public static Problem createProblem(String detail, Object... datas) {
ProblemBuilder builder = Problem.builder().withDetail(detail).with("code", 0);
for(Object obj:datas){
String name = getName(obj);
builder.with(name,obj);
}
return builder.build();
}
public static Problem createProblem(String detail, int code, Object... datas) {
ProblemBuilder builder = Problem.builder().withDetail(detail).with("code", code);
for(Object obj:datas){
String name = getName(obj);
builder.with(name,obj);
}
return builder.build();
}
private static String getName(Object obj){
String name = null;
if(obj instanceof List){
name = ((List) obj).get(0).getClass().getName()+"s";
}else {
name = obj.getClass().getName();
}
return tolowFirstCase(name.substring(name.lastIndexOf(".")+1));
}
private static String tolowFirstCase(String str) {
char[] c = str.toCharArray();
c[0] = (char) (c[0]-(32)); //ASCII
return c.toString();
}
}
建义在mybatis-start里添加对mybatis-plus的支持,这样对于单表的操作,基本上不用写任何sql
`@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class,DataSourceTransactionManagerAutoConfiguration.class })
@EnableTransactionManagement
public class SampleMybatisApplication {
public static void main(String[] args) throws Exception {
SpringApplication app = new SpringApplication(
SampleMybatisApplication.class);
app.run(args);
}
@Autowired
private HotMapper hotMapper;
@Autowired
private SecondHotMapper secondHotMapper;
@Transactional("firstTransactionManager")
@RequestMapping(value = "/transactional1", method = RequestMethod.GET)
public String transactional1() {
hotMapper.deleteById(10);
return "";
}
@Transactional("secondTransactionManager")
@RequestMapping(value = "/transactional2", method = RequestMethod.GET)
public String transactional2() {
secondHotMapper.deleteById(10);
return "";
}
}`
我的HotMapper 和 SecondHotMapper 是对应两个数据源的mapper,如果想添加事务的时候就必须像上面代码一样指定Transactional的名字,请问大神有什么好的办法,不需要业务层去关心当前使用的哪个事务么?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.