Skip to content

Instantly share code, notes, and snippets.

@logicjwell
logicjwell / SpringContextUtils.java
Last active April 30, 2019 05:35
[SpringContextUtils] 在非spring管理bean中读取spring上下文里的bean #spring #上下文
/* *
*
* @Description Spring的ApplicationContext的持有者,可以用静态方法的方式获取spring容器中的bean
* @Date 21:07 2018/4/18
*/
@Component
public class SpringContextHolder implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@logicjwell
logicjwell / FileUploaderController.java
Created April 28, 2019 03:37
[springboot中上传文件的服务接口] #springboot #上传
@ApiOperation("上传需求单附件")
@PostMapping(value = "${order-trade.mgmt.requirement}/upload/{requirementUuid}",
consumes = "multipart/*",
headers = "content-type=multipart/form-data")
public JsonResult upload(@PathVariable String requirementUuid,
@ApiParam(value = "上传文件", required = true) MultipartFile file,
@RequestHeader(Constant.HTTP_SECURITY_HEADER) String token){
UserInfo userinfo = getUserInfo(token);
String myUuid = userinfo.getUuid();
@logicjwell
logicjwell / TestRequirementMapper.java
Last active April 28, 2019 12:45
[MyBatis基于注解的one-to-one, one-to-many关联查询] #mybatis #关联查询 #OneToOne #OneToMany
@Mapper
public interface TestRequirementMapper {
@Results(id = "requirementResult", value = {
@Result(column="uuid",property="uuid", id = true),
@Result(column="requirement=uuid, creator=myUuid",property="attachments", many = @Many(select = "selectAttachmentsByRequirement")),
@Result(column="name_of_requirement",property="name_of_requirement"),
@Result(column="cat_of_requirement",property="cat_of_requirement"),
@Result(column="statement_of_material",property="statement_of_material"),
@Result(column="statement_of_processing",property="statement_of_processing"),
@Result(column="estimate_price",property="estimate_price"),
@logicjwell
logicjwell / application.yml
Created April 26, 2019 10:49
[springboot 配置文件常用配置项及说明] #springboot #配置文件
spring:
profiles:
active: test
error:
include-exception: true
include-stacktrace: always
undertow:
accesslog:
dir: /data/logs/huacai-order-trade
enabled: true
@logicjwell
logicjwell / PageHelper.java
Created April 26, 2019 10:45
[springboot中PageHelper配置与使用] #pagehelper #springboot
1.配置:
pagehelper:
reasonable: false
params:
page-num: pageHelperStart
page-size: pageHelperRows
count: countSql
offset-as-page-num: true
support-methods-arguments: true
@logicjwell
logicjwell / Maven.xml
Created April 26, 2019 09:41
[Maven中配置仓库镜像] #maven
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
@logicjwell
logicjwell / WebMvcConfiguration.java
Last active April 29, 2019 10:54
[springboot中mvc常用配置] #springboot #spring-mvc
@Configuration
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
/**
* 跨域配置
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedHeaders("*")
@logicjwell
logicjwell / MybatisConfiguration.java
Created April 26, 2019 09:31
[Mybatis 在springboot中的配置] #mybatis #springboot
@Configuration
@MapperScan(basePackages = {"com.huacai.counter.jzb.biz.repositories.mappers"})
@EnableConfigurationProperties(DataSourceProperties.class)
@EnableTransactionManagement
public class MybatisConfiguration {
}
@logicjwell
logicjwell / JacksonUtils.java
Last active April 26, 2019 09:28
[jackson 工具函数] #jackson
private final static ObjectMapper OBJECT_MAPPER=new ObjectMapper();
static {
OBJECT_MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL);
OBJECT_MAPPER.configure(SerializationFeature.INDENT_OUTPUT, Boolean.TRUE);
OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
/**
* <p>