-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
419 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.huifer.design.factory.simple; | ||
|
||
import com.huifer.design.factory.MengNiu; | ||
import com.huifer.design.factory.Milk; | ||
import com.huifer.design.factory.YiLi; | ||
|
||
/** | ||
* <p>Title : SimpleFactory </p> | ||
* <p>Description : 牛奶的简单工厂</p> | ||
* | ||
* @author huifer | ||
* @date 2019-05-15 | ||
*/ | ||
public class SimpleFactory { | ||
|
||
public Milk getMilk(String name) { | ||
if ("蒙牛".equals(name)) { | ||
return new MengNiu(); | ||
} else if ("伊利".equals(name)) { | ||
return new YiLi(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.huifer.rbac.entity.res.user; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode | ||
public class UserQueryRes { | ||
private String userName; | ||
|
||
private LocalDateTime createTime; | ||
|
||
private Long createUser; | ||
|
||
private LocalDateTime updateTime; | ||
|
||
private Long updateUser; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.huifer.springmybatis.mapper; | ||
|
||
import org.apache.ibatis.annotations.Param; | ||
|
||
/** | ||
* 描述: | ||
* 转账 | ||
* | ||
* @author huifer | ||
* @date 2019-03-10 | ||
*/ | ||
public interface AccountMapper { | ||
/** | ||
* 更新记录 | ||
* | ||
* @param name | ||
* @param money | ||
*/ | ||
void update(@Param("name") String name, @Param("money") double money); | ||
|
||
/** | ||
* 查询记录 | ||
* | ||
* @param name | ||
* @return | ||
*/ | ||
double queryMoney(@Param("name") String name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.ibatis.type; | ||
|
||
import java.sql.CallableStatement; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.time.ZonedDateTime; | ||
|
||
/** | ||
* @since 3.4.5 | ||
* @author Tomas Rohovsky | ||
*/ | ||
public class ZonedDateTimeTypeHandler extends BaseTypeHandler<ZonedDateTime> { | ||
|
||
@Override | ||
public void setNonNullParameter(PreparedStatement ps, int i, ZonedDateTime parameter, JdbcType jdbcType) | ||
throws SQLException { | ||
ps.setObject(i, parameter); | ||
} | ||
|
||
@Override | ||
public ZonedDateTime getNullableResult(ResultSet rs, String columnName) throws SQLException { | ||
return rs.getObject(columnName, ZonedDateTime.class); | ||
} | ||
|
||
@Override | ||
public ZonedDateTime getNullableResult(ResultSet rs, int columnIndex) throws SQLException { | ||
return rs.getObject(columnIndex, ZonedDateTime.class); | ||
} | ||
|
||
@Override | ||
public ZonedDateTime getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { | ||
return cs.getObject(columnIndex, ZonedDateTime.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.ibatis.submitted.lazyload_common_property; | ||
|
||
public interface FatherMapper { | ||
Father selectById(Integer id); | ||
} |
133 changes: 133 additions & 0 deletions
133
docs/spring/cs93d7c52a-4ec0-11ee-a0fd-acde48001122.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package com.huifer.utils.controller; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import net.sf.cglib.beans.BeanGenerator; | ||
import net.sf.cglib.beans.BeanMap; | ||
import org.apache.commons.beanutils.BeanUtils; | ||
import org.apache.commons.beanutils.PropertyUtilsBean; | ||
//import org.springframework.cglib.beans.BeanGenerator; | ||
//import org.springframework.cglib.beans.BeanMap; | ||
|
||
import java.beans.PropertyDescriptor; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ReflectUtil { | ||
|
||
|
||
public static Object getTarget(Object source, Map<String, Object> addProperties) { | ||
// 获取原始数据的value | ||
PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean(); | ||
PropertyDescriptor[] descriptors = propertyUtilsBean.getPropertyDescriptors(source); | ||
Map<String, Class> propertyMap = new HashMap<>(); | ||
for (PropertyDescriptor d : descriptors) { | ||
if (!"class".equalsIgnoreCase(d.getName())) { | ||
propertyMap.put(d.getName(), d.getPropertyType()); | ||
} | ||
} | ||
// 增加数据的值 | ||
addProperties.forEach((k, v) -> propertyMap.put(k, v.getClass())); | ||
// 创建原始数据的实体对象 | ||
DynamicBean dynamicBean = new DynamicBean(source.getClass(), propertyMap); | ||
// 老数据 | ||
propertyMap.forEach((k, v) -> { | ||
try { | ||
if (!addProperties.containsKey(k)) { | ||
dynamicBean.setValue(k, propertyUtilsBean.getNestedProperty(source, k)); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
}); | ||
// 添加新数据 | ||
addProperties.forEach((k, v) -> { | ||
try { | ||
dynamicBean.setValue(k, v); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
}); | ||
Object target = dynamicBean.getTarget(); | ||
return target; | ||
} | ||
|
||
|
||
public static void main(String[] args) throws Exception { | ||
BaseBase entity = new BaseBase(); | ||
Map<String, Object> addProperties = new HashMap() {{ | ||
put("username", "username"); | ||
put("pwd", "pwd"); | ||
put("hcName", "hcName"); | ||
put("hcName1", "hcName"); | ||
put("hcName2", "hcName"); | ||
}}; | ||
Object target = getTarget(entity, addProperties); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
String json = mapper.writeValueAsString(target); | ||
System.out.println(json); | ||
StuFat stuFat = new StuFat(); | ||
BeanUtils.copyProperties(stuFat, target); | ||
System.out.println(); | ||
} | ||
|
||
|
||
/** | ||
* 动态bean | ||
*/ | ||
public static class DynamicBean { | ||
/** | ||
* 目标对象 | ||
*/ | ||
private Object target; | ||
|
||
/** | ||
* 属性集合 | ||
*/ | ||
private BeanMap beanMap; | ||
|
||
public DynamicBean(Class superclass, Map<String, Class> propertyMap) { | ||
this.target = generateBean(superclass, propertyMap); | ||
this.beanMap = BeanMap.create(this.target); | ||
} | ||
|
||
|
||
/** | ||
* bean 添加属性和值 | ||
* | ||
*/ | ||
public void setValue(String property, Object value) { | ||
beanMap.put(property, value); | ||
} | ||
|
||
/** | ||
* 获取属性值 | ||
* | ||
*/ | ||
public Object getValue(String property) { | ||
return beanMap.get(property); | ||
} | ||
|
||
/** | ||
* 获取对象 | ||
* | ||
*/ | ||
public Object getTarget() { | ||
return this.target; | ||
} | ||
|
||
|
||
/** | ||
* 根据属性生成对象 | ||
* | ||
*/ | ||
private Object generateBean(Class superclass, Map<String, Class> propertyMap) { | ||
BeanGenerator generator = new BeanGenerator(); | ||
if (null != superclass) { | ||
generator.setSuperclass(superclass); | ||
} | ||
BeanGenerator.addProperties(generator, propertyMap); | ||
return generator.create(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.huifer.aop.advisor; | ||
|
||
/** | ||
* 描述: | ||
* | ||
* @author huifer | ||
* @date 2019-03-02 | ||
*/ | ||
public class WoMan implements BaseAopPointCut { | ||
@Override | ||
public void eat() { | ||
System.out.println("吃饭了"); | ||
} | ||
|
||
@Override | ||
public void wc() { | ||
System.out.println("上厕所"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.github.huifer.full.shiro.rest; | ||
|
||
import com.github.huifer.full.shiro.model.req.resourece.ResourceCreateParam; | ||
import com.github.huifer.full.shiro.model.res.ResultVO; | ||
import com.github.huifer.full.shiro.service.ResourceService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/role") | ||
public class RoleController { | ||
|
||
@Autowired | ||
private ResourceService resourceService; | ||
|
||
@PostMapping("/") | ||
public ResultVO create(@RequestBody ResourceCreateParam param) { | ||
return ResultVO.success(this.resourceService.create(param)); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResultVO update(@RequestBody ResourceCreateParam param, @PathVariable("id") int id) { | ||
return ResultVO.success(this.resourceService.update(param, id)); | ||
|
||
} | ||
|
||
@DeleteMapping("/") | ||
public ResultVO delete(@PathVariable("id") int id) { | ||
return ResultVO.success(this.resourceService.delete(id)); | ||
|
||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResultVO byId(@PathVariable("id") int id) { | ||
return ResultVO.success(this.resourceService.byId(id)); | ||
} | ||
} |
Oops, something went wrong.