小编Oui*_*sal的帖子

如何在 Android Studio 中添加测试文件夹

我正在处理一个删除了测试文件夹的项目,我想做一个单元测试。有没有办法为这个项目再次创建测试文件夹?

testing android android-studio

7
推荐指数
4
解决办法
5813
查看次数

403 ajax GET请求Spring的禁止错误

403 forbidden每次我GET从数据库中尝试用户的信息时,我都会得到一个错误.关于我下面的代码,每次我按下Ajax测试按钮尝试请求时,它都无法运行并给我一个警报,但在控制台中也给了我一个403 Forbidden错误.我不确定它是否与Spring安全性有关?

用户JSP页面:

<table>
    <tr>
        <td>User Id</td>
        <td>Full Name</td>
        <td>Username</td>
        <td>Email</td>
        <td>Date of Birth</td>
        <td>User Authority</td>
        <td>Update </td>
        <td>Delete</td>
    </tr>
    <c:forEach var="user" items="${users}">
        <tr>
            <td><c:out value="${user.id}" /></td>
            <td><c:out value="${user.name}"/></td>
            <td><c:out value="${user.username}"/></td>
            <td><c:out value="${user.email}"/></td>
            <td><c:out value="${user.dob}"/></td>
            <td><c:out value="${user.authority}"/></td>
            <td>
                <a id="update" href="<c:url value="/viewUser"><c:param name="id" value="${user.id}"/></c:url>"><button>Update</button></a>
            </td>
            <td>
                <a id="delete" href="<c:url value="/deleteUser"><c:param name="id" value="${user.id}"/></c:url>"><button>Delete</button></a>
            </td>
            <td>
                <button class="loadUser" name="id" value="${user.id}">Ajax test</button>
            </td>
        </tr>
    </c:forEach>
</table>
 <div id="personIdResponse"> </div>
<script type="text/javascript">
    $(document).ready(function(){
        $(".loadUser").click(function(e) {
            e.preventDefault(); …
Run Code Online (Sandbox Code Playgroud)

java ajax jquery spring spring-mvc

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

在 Spring 应用程序中拥有 RestController 和 Controller 的最佳实践

我不是在问是否有可能,我知道有可能,但我想知道在我的应用程序中有前端的同时提供休息服务的最佳方式是什么。

我正在开发一个 Spring Boot 应用程序,我目前有一个调用 jsp 页面的控制器和一个单独的RestController。我希望能够使用 Android 应用程序使用它。

那么在我的应用程序中同时拥有一个 Controller 和一个单独的Restcontroller是否正确?例如,将从 /api/* 调用 Rest 控制器方法。


编辑:我知道两者之间的区别,但是由于我希望能够返回视图(并且我不应该使用 RestController 来这样做)并且我想要一个休息服务我想知道我是否可以同时拥有他们(当然是分开的)。

非常感谢你。

java rest spring

6
推荐指数
1
解决办法
3569
查看次数

Spring Rest应用程序中的“不支持内容类型'application / json; charset = UTF-8'”

当我在localhost:8080 / api / users上执行POST请求以创建新用户时,出现以下错误:

{
"timestamp": "2018-05-28T09:44:55.704+0000",
"status": 415,
"error": "Unsupported Media Type",
"message": "Content type 'application/json;charset=UTF-8' not supported",
"path": "/api/users/"
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

是请求的正文,已选择JSON(application / json)。即使我删除了角色并将其保留为空,它也会给出相同的错误。

在此处输入图片说明

标头的内容类型也是application / json。

在此处输入图片说明

这是我的控制器:

@PostMapping("/api/users" )
public User createUser(@Valid @RequestBody User user) {
    securityService.autologin(user.getUsername(), user.getPassword());
    return userService.createUser(user);
}
Run Code Online (Sandbox Code Playgroud)

UserService中的createUser函数:

   public User createUser(@Valid @RequestBody User user) {
    user.setPassword(bCryptPasswordEncoder.encode(user.getPassword()));
    user.setRoles(new HashSet<>(roleRepository.findAll()));
    return userRepository.save(user);
}
Run Code Online (Sandbox Code Playgroud)

编辑

这是我的User类:

@Entity
@Table(name = "user")
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"createdAt", "updatedAt"}, 
    allowGetters = true)
public class User implements Serializable{

private …
Run Code Online (Sandbox Code Playgroud)

java rest spring httprequest postman

6
推荐指数
2
解决办法
2万
查看次数

bash:export:`-Xmx512m':当我设置MAVEN_OPTS变量时,它不是有效的标识符

我在使用OpenSuse,我正在按照本教程设置Maven.

当我跑这个:

export MAVEN_OPTS=-Xms256m -Xmx512m
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

bash:export:`-Xmx512m':不是有效的标识符

我按照该教程的步骤操作,我下载的Maven是版本3.5.2.

linux bash opensuse maven

5
推荐指数
2
解决办法
1913
查看次数

有没有办法让这个故障的堆栈跟踪调用Broken管道服务包?

我试图使用Android Studio在我的Android设备上运行我的应用程序,它运行正常,但在这种情况下,一些数据正在从我的手机中删除,虽然该过程尚未完成,但Android工作室正在尝试安装和运行该应用程序导致我的手机卡住一段时间并重新启动.

所以我想知道是否有办法获得错误的完整堆栈跟踪,这是否意味着我的应用程序可能没有正确的结构并在重要进程中被杀死?

谢谢.

这是我当时得到的错误:

安装失败,显示消息无法完成会话:未知故障(cmd:调用服务包失败:管道损坏(32)).

通过卸载现有版本的apk(如果存在)然后重新安装,可能会解决此问题.


PS:我不是在问我如何解决这个错误,因为我的应用程序运行,我想了解可能导致它的原因.

java android interop scheduled-tasks

5
推荐指数
1
解决办法
1153
查看次数

有没有办法在 Visual Studio 搜索/替换中插入换行符?

是否可以在 Visual Studio 中搜索特定关键字并将其替换为代码块而不删除换行符?

例如,我想搜索:

SearchKeyword
Run Code Online (Sandbox Code Playgroud)

并将其替换为:

Line1
Line2
Line3
Line4
Run Code Online (Sandbox Code Playgroud)

当然,假设上面的代码块很长并且不是我可以使用 Visual Studio 或其他工具自动格式化的代码。

c# visual-studio

2
推荐指数
1
解决办法
447
查看次数

我应该将哪个版本的 okhttp 和 okhttp 日志记录拦截器与 Retrofit 2.1.0 一起使用以避免此错误?

运行改造应用程序时出现以下错误:

E/AndroidRuntime:致命异常:OkHttp 调度程序进程:fr.univ_lehavre.greah.naoderapp,PID:20894 java.lang.NoSuchMethodError:类 Lokhttp3/internal/Platform 中没有虚拟方法日志(Ljava/lang/String;)V;或其超类('okhttp3.internal.Platform' 声明出现在 /data/app/fr.univ_lehavre.greah.naoderapp-2/split_lib_dependency_apk.apk 中)位于 okhttp3.logging.HttpLoggingInterceptor$Logger$1.log(HttpLoggingInterceptor.java :108)在okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:157)在okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:190)在okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)在okhttp3.RealCall .access$100(RealCall.java:30) 在 okhttp3.RealCall$AsyncCall.execute(RealCall.java:127) 在 okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 在 java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1133) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 在 java.lang.Thread.run(Thread.java:761)

这是我创建改造对象的类:

public class RetrofitImpl {

private static Retrofit retrofit = null;
public static final String BASE_URL = "http://192.168.43.144:8080/";
//    public static final String BASE_URL = "http://10.0.2.2:8080/";

public static Retrofit getClient() {

    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

    retrofit = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .client(client)
            .build();
    return retrofit;
}
Run Code Online (Sandbox Code Playgroud)

}

我不确定应该使用哪个版本。

这些是我目前正在使用的:

implementation …
Run Code Online (Sandbox Code Playgroud)

rest android retrofit okhttp

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

Spring Boot:错误:代理抛出的异常:java.net.MalformedURLException:本地主机名未知

我已经在 Eclipse (STS 3.9.2) 上安装了 Spring Tool Suite,我创建了一个演示应用程序,但是当我将它作为“Spring Boot App”运行时,我收到以下错误:

错误:代理抛出的异常:java.net.MalformedURLException:本地主机名未知:java.net.UnknownHostException:linux-se15:linux-se15:名称或服务未知

运行此命令会产生以下结果:

  hostname --fqdn
  hostname: Name or service not known
Run Code Online (Sandbox Code Playgroud)

/etc/hosts 有以下内容:

127.0.0.1   localhost

# special IPv6 addresses
::1             localhost ipv6-localhost ipv6-loopback

fe00::0         ipv6-localnet

ff00::0         ipv6-mcastprefix
ff02::1         ipv6-allnodes
ff02::2         ipv6-allrouters
ff02::3         ipv6-allhosts
Run Code Online (Sandbox Code Playgroud)

java linux spring spring-boot

0
推荐指数
1
解决办法
3211
查看次数