小编Dar*_*man的帖子

如何使用Swagger注释在Swagger中设置描述和示例?

我正在使用Spring启动创建REST Api,并使用swagger codegen在控制器中自动生成swagger文档.但是,我无法在POST请求中为String类型的参数设置描述和示例.这是mi代码:

import io.swagger.annotations.*;

@Api(value = "transaction", tags = {"transaction"})
@FunctionalInterface
public interface ITransactionsApi {
    @ApiOperation(value = "Places a new transaction on the system.", notes = "Creates a new transaction in the system. See the schema of the Transaction parameter for more information ", tags={ "transaction", })
    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "Another transaction with the same messageId already exists in the system. No transaction was created."),
        @ApiResponse(code = 201, message = "The transaction has been …
Run Code Online (Sandbox Code Playgroud)

java spring swagger swagger-codegen

31
推荐指数
3
解决办法
3万
查看次数

如何在DataTable中获取列的SqlType?

我有一个从SQL数据库获得的DataTable,如下所示:

using (SqlCommand cmd = new SqlCommand(query, _sqlserverDB))
{
    using (SqlDataAdapter adapter = new SqlDataAdapter(cmd))
    {
        DataSet dataSet = new DataSet();
        adapter.Fill(dataSet);
        result = (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count > 0) ? dataSet.Tables[0] : null;
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试通过dataColumn.DataType获取每列的DataType时,我得到C#类型(Int32,Int64,String等).

问题:如何访问本机SQL数据类型(varchar,nvarchar,bigint ...)而不是C#类型?

我试过dataColumn.DataType.UnderlyingSystemType,结果是一样的.

c# datacolumn sqldatatypes

19
推荐指数
3
解决办法
4万
查看次数

如何在Android中动态更改按钮样式?

我想动态地改变按钮的样式,即在Java代码中,例如:

((Button)findViewById(id)).setStyle("@styles/foo")

<resources>
    <style name="foo">
        <item name="android:adjustViewBounds">true</item>
        <item name="android:maxHeight">100px</item>
        <item name="android:maxWidth">200px</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

我没有看到像setStyle这样的东西,所以:

我是否必须改变每一个属性或者我可以改变整个风格?

android coding-style button

13
推荐指数
1
解决办法
4万
查看次数

如何将微服务的招摇聚合成一个招摇

我试图在我的微服务项目中生成一个单一的 swagger,在 Api 网关中将所有服务 swagger 聚合成一个单一的服务。为了实现这一点,我正在关注下一个教程https://objectpartners.com/2017/09/28/aggregate-services-into-a-single-swagger

这里的问题是,当我尝试设置绝对 URL 时,我收到的输出是Failed to load API definition。undefined http://localhost:8070/apihttp://localhost:8081/api/v2/api-docs其中localhost:8070/api是 api 网关的基本 URL,而localhost:8081/api/v2/api-文档是微服务 swagger 的 docs URL。

这是我的代码:

Swagger配置

package com.rfd.apigateway.swagger;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
@ConfigurationProperties(prefix = "swagger")
public class SwaggerConfiguration {

    private List<Resource> resources;

    public List<Resource> getResources() {
        return resources;
    }

    public void setResources(List<Resource> resources) {
        this.resources = resources;
    }
}
Run Code Online (Sandbox Code Playgroud)

资源

package com.rfd.apigateway.swagger;

public class Resource {
    private String name;
    private String url;
    private …
Run Code Online (Sandbox Code Playgroud)

swagger api-gateway

8
推荐指数
1
解决办法
6432
查看次数

Android加密BadPaddingException

我正在制作一个Android应用程序,我想在将其发送到DataBase之前对其进行加密,并且加密是正确的.解密String时会出现问题,因为我收到了BadPaddingException并且我不知道问题出在哪里.这是代码:

public final static String HEX = "36A52C8FB7DF9A3F";

public static String encrypt(String seed, String cleartext) throws Exception 
{
    byte[] rawKey = getRawKey(seed.getBytes());
    byte[] result = encrypt(rawKey, cleartext.getBytes());
    return toHex(result);
}

public static String decrypt(String seed, String encrypted) throws Exception 
{
    byte[] rawKey = getRawKey(seed.getBytes());
    byte[] enc = toByte(encrypted);
    byte[] result = decrypt(rawKey, enc);
    return new String(result);
}

public static String toHex(String txt) {
    return toHex(txt.getBytes());
}

public static String fromHex(String hex) {
    return new String(toByte(hex));
}

public static byte[] toByte(String …
Run Code Online (Sandbox Code Playgroud)

encryption android exception

5
推荐指数
0
解决办法
7306
查看次数

Linq to Entities:添加一个没有保存更改的对象

我们假设我有以下代码:

TEModule teModule = Context.TEModules.Where(module => module.EnumValue.Equals(text.ModuleName)).FirstOrDefault();
if (teModule == null)
{
     teModule = new TEModule();
     teModule.EnumValue = text.ModuleName;
     Context.TEModules.AddObject(teModule);
     //Context.SaveChanges();
     TEModule aux = Context.TEModules.Where(module => module.EnumValue.Equals(teModule.ModuleName)).FirstOrDefault();
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,如果我保持" SaveChanges "注释,那么在下一个查询中,aux对象始终为null,因为Context.TEModules为空,即使我调用" AddObject "方法也是如此.但是,如果我在AddObject之后调用SaveChanges,那么在下一个查询中,aux对象不为null.问题是我不想经常调用SaveChanges,因为这不是我添加对象的唯一代码片段,如果我这样做,性能会下降.

所以问题是:我是否必须在每次AddObject调用后调用SaveChanges,如果以后我需要知道对象是否已经存在?

linq-to-entities entity-framework add savechanges

4
推荐指数
1
解决办法
1862
查看次数

Springboot:如何执行具有真实依赖项的集成测试?

我现在开始学习 Java 和 Spring boot,我在集成测试中遇到了依赖注入的一些问题。我在src/main/java/com/rfd/domain/services下有一个名为 TransactionService 的类,它被标记为 @Service 并且它有另一个依赖项,其中一个是由 Spring Boot 创建的存储库。当我启动应用程序时,它会正确启动,因此我假设依赖项正在正确解析。这是总结类:

package com.rfd.domain.services;

import allNeededImports

@Service
public class TransactionsService {

    @Autowired
    private KambiTransactionRepository kambiTransactionRepository;

    @Autowired
    private TransactionFactory transactionFactory;

    public List<Transaction> retrieveTransactions(String couponExternalId) throws InvalidTransactionException {
        // someCode
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,我在/src/test/java/com/rfd/integrationtests/domain/services下有一个 TransactionsServiceTests 类:

package com.rfd.integrationtests.domain.services;
import allNeededImports

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Main.class)
@DataMongoTest
@TestPropertySource(locations = "classpath:application-integrationtest.properties")
public class TransactionsServiceTests {

    @Autowired
    private TransactionsService transactionsService;

    @Test
    public void retrieveTransactions_happyPathMultipleTransactions_transactionsRetrieved() throws InvalidTransactionException {
        // test code
    }
Run Code Online (Sandbox Code Playgroud)

当我尝试启动测试时,收到以下错误:

引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的“com.rfd.domain.services.TransactionsService”类型的合格bean:预计至少有1个bean有资格作为自动装配候选。依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)} …

java integration-testing dependency-injection spring-boot

4
推荐指数
1
解决办法
3862
查看次数