我正在开发演示REST服务,使用Spring Boot
用户必须登录才能执行某些操作子集.Swagger UI
使用springfox
该简单配置添加(使用库)后:
@Bean
public Docket docApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(any())
.paths(PathSelectors.ant("/api/**"))
.build()
.pathMapping("/")
.apiInfo(apiInfo())
.directModelSubstitute(LocalDate.class, String.class)
.useDefaultResponseMessages(true)
.enableUrlTemplating(true);
}
Run Code Online (Sandbox Code Playgroud)
我最终得到了所有apis与Swagger UI
页面上列出的所有操作.不幸的是,我没有在其中列出登录/注销端点.
问题是部分操作无法通过Swagger UI
内置形式执行(我发现它非常好用,并希望使其工作),因为用户没有登录.有没有解决这个问题的方法?我可以手动定义一些端点Swagger
吗?
如果有表单提交凭证(即登录/注销端点),我可以在使用该安全端点之前执行授权.然后,Swagger
用户可以token/sessionid
从响应中提取并将其粘贴到通过定义的自定义查询参数@ApiImplicitParams
.
您可以在下面找到我的安全配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.loginProcessingUrl("/api/login")
.usernameParameter("username")
.passwordParameter("password")
.successHandler(new CustomAuthenticationSuccessHandler())
.failureHandler(new CustomAuthenticationFailureHandler())
.permitAll()
.and()
.logout()
.logoutUrl("/api/logout")
.logoutSuccessHandler(new CustomLogoutSuccessHandler())
.deleteCookies("JSESSIONID")
.permitAll()
.and()
.csrf()
.disable()
.exceptionHandling()
.authenticationEntryPoint(new CustomAuthenticationEntryPoint())
.and()
.authorizeRequests()
.and() …
Run Code Online (Sandbox Code Playgroud) 我正在编写一个模板,该模板应该呈现员工列表.员工以部门列表的形式传递给Thymeleaf,每个部门都有自己的员工列表.
我的任务是展示所有 - 问题是处理连续的计算.每个员工应显示为下一个号码的行.
以下尝试允许索引给定部门的员工,每个部门都有新的编号:
<table th:each="department, depStatus : departmentList">
<tr th:each="employee, empStatus : department.employees">
<td th:inline="text">[[${empStatus.index+1}]]</td>
Run Code Online (Sandbox Code Playgroud)
但我的观点是要通过所有部门保持连续计算,就像这样:
1. Employee A from Dept X
2. Employee B from Dept X
3. Employee C from Dept Y
Run Code Online (Sandbox Code Playgroud)
我知道我可以在服务器端使这个结构平坦,但我不能相信这是唯一的方法.
我也尝试过引入局部变量,th:with="idx = 0"
然后在某处增加它th:with="idx = ${idx} + 1
,但这只是覆盖了外部idx
值.
我被困在转换Java Bean
中Map
.互联网上有很多资源,但不幸的是,它们都将简单的bean转换为地图.我的那些更广泛.
有简化的例子:
public class MyBean {
private String firstName;
private String lastName;
private MyHomeAddress homeAddress;
private int age;
// getters & setters
}
Run Code Online (Sandbox Code Playgroud)
我的观点是生产Map<String, Object>
哪种,在这种情况下,对于以下条件是正确的:
map.containsKey("firstName")
map.containsKey("lastName")
map.containsKey("homeAddress.street") // street is String
map.containsKey("homeAddress.number") // number is int
map.containsKey("homeAddress.city") // city is String
map.containsKey("homeAddress.zipcode") // zipcode is String
map.containsKey("age")
Run Code Online (Sandbox Code Playgroud)
我试过用Apache Commons BeanUtils
.这两种方法BeanUtils#describe(Object)
,并BeanMap(Object)
产生一个地图,"深层次"为1(我的意思是这里只有"homeAddress"
钥匙,拿着MyHomeAddress
对象的值).我的方法应该越来越深入地进入对象,直到它遇到基本类型(或字符串),然后它应该停止挖掘和插入键即"order.customer.contactInfo.home"
.
所以,我的问题是:如何轻松完成(或者是否已经存在允许我这样做的项目)?
更新
我已经扩展了Radiodef的答案,还包括Collections,Maps Arrays和Enums:
private static boolean isValue(Object value) { …
Run Code Online (Sandbox Code Playgroud) 我正在研究JPA文档,遇到以下几行:
锁定实体包含外键的实体关系也将被锁定,但不会锁定所引用实体的状态(除非明确锁定这些实体).实体不包含外键的元素集合和关系(例如映射到连接表的关系或目标实体包含外键的单向一对多关系)默认情况下不会被锁定.
它来自这里(PessimisticLockScope.NORMAL
)
我想知道如何解释这些线条.如果PessimisticLockScope
设置为,EXTENDED
则连接表中的行也会被锁定(但不是相关实体本身),所以在使用NORMAL
值时会锁定什么?为了确保实体行(或列,如果继承策略是JOINED
或TABLE_PER_CLASS
,或者如果有SecondaryTable
),但什么意思"实体关系":
锁定的实体包含外键的实体关系也将被锁定
在上下文中PessimisticLockScope.NORMAL
?
我试图实现类似于marquee的效果- 在水平轴上移动的长(在我的情况下)文本的行.我设法让它工作,但我不能称之为令人满意.
我的Controller
课程如下:
@FXML
private Text newsFeedText;
(...)
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
TranslateTransition transition = TranslateTransitionBuilder.create()
.duration(new Duration(7500))
.node(newsFeedText)
.interpolator(Interpolator.LINEAR)
.cycleCount(Timeline.INDEFINITE)
.build();
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
transition.setFromX(width);
transition.setToX(-width);
transition.play();
}
Run Code Online (Sandbox Code Playgroud)
newsFeedText
绑定到一些动态更新的文本源,因此它包含不同数量的文本.
我的代码至少有两个缺点:
-width
到+width
; width
是显示器的分辨率宽度如果窗口没有经过全面筛选,有时会看不到文本.如果文本更长并且newsFeedText
宽度将大于显示器的分辨率宽度,则转换将"消失"(仍然在屏幕上).
Duration
不依赖于宽度newsFeedText
.现在,它没有任何意义,但如果过渡fromX
和toX
动态计算,那么它将导致各种速度的选框.
如何摆脱这些弊端?
我很简单的应用程序具有保存/加载其当前状态的功能.保存功能如下所示:
doSave :: BoardType -> Field -> [Char] -> Bool
doSave board player fileName = do
let x = encodeFile fileName (board :: BoardType, player :: Field)
True -- there will be exception handling
Run Code Online (Sandbox Code Playgroud)
我的加载功能:
doLoad :: [Char] -> IO (BoardType, Field)
doLoad fileName = decodeFile fileName :: IO (BoardType, Field)
Run Code Online (Sandbox Code Playgroud)
并且有我的问题,加载后,我有 IO (BoardType, Field)
不适合我的程序和其他可能不应接受IO
参数的函数.如果我跟着这个IO
升级,IO
我的应用程序中就会有所有内容- 是否有必要(或者 - 使用haskell语言正常)?
最后 - 有一种简单的方法可以摆脱这种情况IO
吗?
是否可以在JPA中指定自定义连接条件(jpql或通过条件api?
select .. from .. join ... on (... <custom criteria> )
Run Code Online (Sandbox Code Playgroud)
我需要这个的原因是因为我想在日期范围内加入一组表(一个是具有事实堆叠的历史表)
**更新**
可以在JPA(2.1>)中指定其他连接条件/条件.见接受的答案(zxcf).
Hibernate注意:虽然可以使用JOIN .. ON或使用javax.persistence.criteria.JOIN编程式指定其他连接条件,但是不能使用引用不同表的条件,只能引用同一个表的条件(和支持不高于层次结构)请参阅:https://hibernate.atlassian.net/browse/HHH-7321
我想使用此方法返回一个Course对象,但前提是该对象不为null.
public Course getClass1()
{
if(class1 != null)
{
return class1;
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个'缺少返回语句'错误,因为它可能不会返回任何内容,但如果对象为null,我不想返回任何内容,甚至不返回空字符串.我可以将方法更改为void
public void getClass1()
{
if(class1 != null)
{
System.out.println(class1);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我这样做,我无法调用toString中的方法
public String toString()
{
return super.getName() + "\t" + super.getAge() + "\t" + getStudentNumber() +
"\n" + getClass1() + "\n" + getClass2() + "\n" + getClass3();
}
Run Code Online (Sandbox Code Playgroud)
因为不允许使用void类型.
java ×6
jpa ×2
haskell ×1
hibernate ×1
if-statement ×1
javabeans ×1
javafx ×1
javafx-2 ×1
jpql ×1
locking ×1
marquee ×1
monads ×1
spring-boot ×1
springfox ×1
sql ×1
swagger ×1
swagger-ui ×1
thymeleaf ×1
transactions ×1