V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  huifer  ›  全部回复第 5 页 / 共 8 页
回复总数  158
1  2  3  4  5  6  7  8  
2021-06-02 16:14:48 +08:00
回复了 Er1c0 创建的主题 问与答 sourcetree 怎么在显示上 分隔 公司 与 非公司 的项目
点击新建文件夹
2021-06-01 17:20:26 +08:00
回复了 amrom 创建的主题 Java 关于微服务多模块问题
2021-05-26 13:15:15 +08:00
回复了 Aliberter 创建的主题 Java 求助! springboot 如何获取 url 上的参数,@PathVariable 复用问题
@Aliberter
解决方案为开启一个独立的 servlet,具体在 springboot 中注入方式如下:

```
@Component
@ComponentScan("com.example.demo.*")
public class Beans {
@Autowired
private ApplicationContext context;

@Bean
public ServletRegistrationBean viewRedisServlet() {
ServletRegistrationBean<Servlet> servletServletRegistrationBean = new ServletRegistrationBean<>();
CustomerServlet servlet = new CustomerServlet();
servlet.setContext(context);

servletServletRegistrationBean.setServlet(servlet);
return servletServletRegistrationBean;
}
}
```

第二步编写 servlet 具体代码如下:

```
@WebServlet
public class CustomerServlet extends HttpServlet {
Gson gson = new Gson();
private ApplicationContext context;

public ApplicationContext getContext() {
return context;
}

public void setContext(ApplicationContext context) {
this.context = context;
}

@SneakyThrows @Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

// 从请求头中获取一个标记,用于确认是需要进行处理的

String c = req.getHeader("is_c");
if (Boolean.valueOf(c)) {

String contextPath = req.getContextPath();
String servletPath = req.getServletPath();

// /{controller}/{action}/{apiVersion}/{userId}/{clientName}
String requestURI = req.getRequestURI();
String[] split = requestURI.split("/");

String controller = null;
String action = null;
String apiVersion = null;
String userId = null;
String clientName = null;
if (split.length == 6) {
controller = split[1];
action = split[2];
apiVersion = split[3];
userId = split[4];
clientName = split[5];
}

// 通过 spring 上下文去搜索 controller + actiron 对应的方法

ApplicationContext tuUse = this.context;
if (StringUtils.hasText(controller)) {
// 找到实例
Object bean = tuUse.getBean(controller);
// 找到执行方法
Method[] methods = bean.getClass().getDeclaredMethods();

Method toCall = null;
for (Method method : methods) {
boolean equals = method.getName().equals(action);
if (equals) {
toCall = method;
break;
}
}
// 获取方法参数类型, 你需要做转换
Class<?>[] types = toCall.getParameterTypes();

// 转换后进行参数使用调用方法
Object invoke = toCall.invoke(bean, apiVersion, userId, clientName);

resp.setContentType("application/json; charset=UTF-8");
resp.getWriter().write(gson.toJson(invoke));
}
System.out.println(contextPath);
}
}

}
```

上述代代码处理流程:

1. 判断是需要进行处理的
2. 将 url 中的 /{controller}/{action}/{apiVersion}/{userId}/{clientName}参数提取
3. 通过成员变量 context 在 spring 中根据名字获取 bean 实例,名字是 controller,通过 spring 中 Component 注解的 value 进行赋值
4. 在 bean 实例种搜索 action 对应的方法,这里要求方法名称和 action 强对应。
5. 将上一步得到的方法提取方法参数,将 url 参数进行类型转换。
6. 反射执行
7. response 返回





其他代码如下:

```
@Data
public class IndexResponse {
private int code;
private Object data;
}
```



```
@Service(value = "home")
public class HomePageController {

public IndexResponse index(
String apiVersion,
String userId,
String clientName) {

IndexResponse response = new IndexResponse();
response.setCode(1);
response.setData(apiVersion + "-" +
userId + "-" +
clientName);
return response;
}

}
```



测试用例如下:

GET http://localhost:8080/home/index/6.0.0/0/Any.

HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
Content-Length: 32
Date: Wed, 26 May 2021 05:14:26 GMT
Keep-Alive: timeout=60
Connection: keep-alive

{
"code": 1,
"data": "6.0.0-0-Any."
}
2021-05-26 12:38:22 +08:00
回复了 Aliberter 创建的主题 Java 求助! springboot 如何获取 url 上的参数,@PathVariable 复用问题
自己写 url 解析写 aop,写拦截器你在自己做类型转换等你写完这个就相当于实现了 spring-mvc 中的路由解析只是没有注解.
不行,无法使用同一个本地仓库
2021-05-19 13:28:54 +08:00
回复了 asdasdasdzxc 创建的主题 程序员 项目的前期架构是否要反复的揣摩一套体系?
需要考虑人员配比,硬件成本、开发时间这些问题。这些问题一次性都来了你就不会想这些。

gitlab commit 强制规范。规范检查谁去做,出现问题如何处理。
git commit before 强制跑 soner 。此处需要额外硬件成本,是否一个项目使用一个 soner,soner 的规则制定谁参与。
测试一个功能一个服务的实例和所有基础服务。不知道想要表达什么。
强制所有模块拆分成为一个,一个 git 远程仓库。拆分模块更多的会拆分服务,按照服务分配多个仓库。
通过 ELK 采集日志集中分析和查看。elk 的硬件资源。
对新表上线必须模拟日增数据。日增的模拟用意是什么?
对服务的监控和熔断,限流。服务监控是基础,熔断限流在项目伊始就应该直接具备,允许额外自定义。
git push master 必须通过所有回归测试。
所有服务必须有基本的 readme.md 介绍。readme 不如产品文档+版本文档+接口文档。
所有的服务必须有版本发布管理。不错
所有的部署必须通过 git 钩子自动化部署的。部署应该手动,避免出现 commit 一次部署一次,会导致硬盘控件暴增
模块的更新必须共同开发的同学一起 code view 。review 的成本很高至少会拖动 2 个人进行时间消耗,review 的时间节点是什么?,能跑就可以。
模块的调用必须通过 feign 或者 MQ 来完成代码的解耦。大可不必
2021-05-13 13:05:55 +08:00
回复了 zhoudaiyu 创建的主题 程序员 大家能推荐一些技术公众号吗?
JustSourceCode
2021-05-09 15:35:47 +08:00
回复了 bingoshe 创建的主题 求职 [广州]三年 Java CRUD boy 求职
学会八股文真实讽刺啊
2021-05-08 09:11:44 +08:00
回复了 yibinhp 创建的主题 Python Python 脚本实现模拟 客户请求 API,求框架推荐
request
2021-05-07 14:30:45 +08:00
回复了 Zhancha 创建的主题 Java jdk 版本兼容性问题
新老项目隔离部署,linux 多 java 环境很方便处理,docker 也是,本机开发可以自己选择 JDK
2021-04-26 20:35:30 +08:00
回复了 Augoror 创建的主题 Apple Mac 有办法精准搜索文件吗
grep -R
2021-04-23 21:27:12 +08:00
回复了 rv54ntjwfm3ug8 创建的主题 数据库 求推荐 Navicat for PostgreSQL 的开源替代品
DBeaver
2021-04-23 15:13:03 +08:00
回复了 Renco 创建的主题 程序员 数据库设计太拉跨被喷了。
创建人 ID,修改人 ID,创建时间,修改时间,删除标记位(不需要的就不加)常规都加,表字段常用的和非常用的分开设计_core(核心),_extends (拓展)
2021-04-21 09:07:58 +08:00
回复了 hrn961110 创建的主题 Java 求助,关于 spring 源码环境搭建。
在这个流程之外建议先在导入前进行手动编译
1. /gradlew :spring-oxm:compileTestJava
2. /gradlew build -x test
2021-04-21 09:06:40 +08:00
回复了 hrn961110 创建的主题 Java 求助,关于 spring 源码环境搭建。
The following has been tested against IntelliJ IDEA 2016.2.2

## Steps

_Within your locally cloned spring-framework working directory:_

1. Precompile `spring-oxm` with `./gradlew :spring-oxm:compileTestJava`
2. Import into IntelliJ (File -> New -> Project from Existing Sources -> Navigate to directory -> Select build.gradle)
3. When prompted exclude the `spring-aspects` module (or after the import via File-> Project Structure -> Modules)
4. Code away

## Known issues

1. `spring-core` and `spring-oxm` should be pre-compiled due to repackaged dependencies.
See `*RepackJar` tasks in the build and https://youtrack.jetbrains.com/issue/IDEA-160605).
2. `spring-aspects` does not compile due to references to aspect types unknown to
IntelliJ IDEA. See https://youtrack.jetbrains.com/issue/IDEA-64446 for details. In the meantime, the
'spring-aspects' can be excluded from the project to avoid compilation errors.
3. While JUnit tests pass from the command line with Gradle, some may fail when run from
IntelliJ IDEA. Resolving this is a work in progress. If attempting to run all JUnit tests from within
IntelliJ IDEA, you will likely need to set the following VM options to avoid out of memory errors:
-XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=2048m
4. If you invoke "Rebuild Project" in the IDE, you'll have to generate some test
resources of the `spring-oxm` module again (`./gradlew :spring-oxm:compileTestJava`)


## Tips

In any case, please do not check in your own generated .iml, .ipr, or .iws files.
You'll notice these files are already intentionally in .gitignore. The same policy goes for eclipse metadata.

## FAQ

Q. What about IntelliJ IDEA's own [Gradle support]( https://confluence.jetbrains.net/display/IDEADEV/Gradle+integration)?

A. Keep an eye on https://youtrack.jetbrains.com/issue/IDEA-53476
2021-04-19 12:29:39 +08:00
回复了 JustinJie 创建的主题 程序员 使用设计模式的疑问
就单表而言可以尝试模板模式,其他的操作可能并没有办法说直接使用某个设计模式。
2021-04-16 08:48:41 +08:00
回复了 iceteacover 创建的主题 Java 如果有个 CRUD 工具会不会有兴趣用?
mybatis 和 JPA 应该大差不差没必要太过于纠结使用谁,要说存在迁移数据库的话我可能选择 JPA 。mybatis 版本的 CRUD 插件也有 https://gitee.com/pychfarm_admin/crud @iceteacover
2021-04-15 15:19:14 +08:00
回复了 iceteacover 创建的主题 Java 如果有个 CRUD 工具会不会有兴趣用?
2021-04-13 15:37:11 +08:00
回复了 005008 创建的主题 程序员 收徒计划可能失败了...
有没有 Java 大佬带带兄弟
1  2  3  4  5  6  7  8  
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2601 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 30ms · UTC 13:48 · PVG 21:48 · LAX 06:48 · JFK 09:48
Developed with CodeLauncher
♥ Do have faith in what you're doing.