如何使用 HiltViewModel 库和 jetpack compose 将参数传递给 viewmodel 构造函数 我的代码:
@HiltViewModel
class GetPurchaseViewModel @Inject constructor(val id:Long) : ViewModel() {
private val service= RestModule
var state = MutableStateFlow<State>(State.START)
init{
get(id)
}
private fun get(id:Long){
viewModelScope.launch {
state.value = State.LOADING
try {
val users = withContext(Dispatchers.IO) {
service.getIntance().getPurchase(id)
}
state.value = State.SUCCESLISTPURCHASE(users)
} catch (e: Exception) {
state.value = State.FAILURE(message = e.localizedMessage!!)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在可组合函数中的调用:
val model:GetPurchaseViewModel=hiltViewModel(idUser)
Run Code Online (Sandbox Code Playgroud) 我的JSF Web应用程序显示以下错误:
在ExternalContext中找不到/index.xhtml作为资源.
我的目录结构是:
- Java Resource -- src --- br.com.k19.controle ---- NumeroAleatorioBean.java --- resources - JavaScript Resources - build - WebContent -- META-INF -- Web Pages --- index.xhtml --- formulario.xhtml -- Web-Inf
我需要把我/index.xhtml
的这个结构放在哪里?
如何getStaticProps()
为所有页面复制 nextjs 函数,而不必重复所有页面?
这些是我的页面和布局组件。我想为所有页面添加全局功能,可以吗?可以添加一个全局getStaticProps
函数吗?
索引.tsx
\nimport Link from 'next/link';\nimport Layout from '../components/Layout';\nimport {InferGetStaticPropsType} from 'next';\n\nfunction Index({data}: InferGetStaticPropsType<typeof getStaticProps>) {\n return (\n <Layout\n title="P\xc3\xa1gina - Home"\n description="desenvolvimento web, web development, constru\xc3\xa7\xc3\xa3o de sites"\n title_meta="desenvolvimento web, web development, constru\xc3\xa7\xc3\xa3o de sites"\n description_meta="desenvolvimento web, web development, constru\xc3\xa7\xc3\xa3o de sites"\n site_name="Rafael Web development"\n url="http://localhost:3000/"\n images={data}>\n <div>\n <h1>Hello Next.js INDEX</h1>\n <Link href="/sobre">\n <a>About</a>\n </Link>\n <main></main>\n </div>\n </Layout>\n );\n}\n\nexport const getStaticProps = async () => {\n const res = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试动态更新文本但没有成功。单击按钮,文本就会更新
我正在尝试将我的应用程序更新为新的撰写版本,但它给了我一个我不知道如何修复的错误。当我运行时,错误仍然存在于我的运行中。我的旧项目正常工作,但我想要的是更改版本,如果有人可以帮助我,我将不胜感激
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.quitanda, PID: 10390
java.lang.AbstractMethodError: abstract method "void androidx.lifecycle.DefaultLifecycleObserver.onCreate(androidx.lifecycle.LifecycleOwner)"
at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:36)
at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196)
at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:808)
at android.view.View.dispatchAttachedToWindow(View.java:18355)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3399)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3406)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1796)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1494)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7288)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6923)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:870)
Run Code Online (Sandbox Code Playgroud)
build.gradle(项目)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
task clean(type: …
Run Code Online (Sandbox Code Playgroud) 我在使用 springboot 3.0.0 时遇到问题,它无法识别我的 eureka 服务器和客户端,但在 2.7.4 版本中它可以正常工作,有什么变化吗?
关注我的课程:
api网关:
@SpringBootApplication
@EnableEurekaServer
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序属性:
spring.application.name = api-gateway
server.port = 8761
eureka.client.register-with-eureka = false
eureka.client.fetch-registry = false
eureka.instance.hostname=localhost
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
Run Code Online (Sandbox Code Playgroud)
我的路线:
@EnableDiscoveryClient
@SpringBootApplication
public class RoutingApplication {
public static void main(String[] args) {
SpringApplication.run(RoutingApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序属性:
server.port=8080
spring.application.name=routing
eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
eureka.instance.hostname=localhost
spring.cloud.gateway.discovery.locator.enabled=true
#spring.main.web-application-type=reactive
spring.cloud.gateway.enabled=true
spring.cloud.gateway.routes[0].id=user
spring.cloud.gateway.routes[0].uri=lb://USER
spring.cloud.gateway.routes[0].predicates=Path=/user/**
spring.cloud.gateway.routes[1].id=testes
spring.cloud.gateway.routes[1].uri=lb://TESTES
spring.cloud.gateway.routes[1].predicates=Path=/testes/**
spring.cloud.gateway.routes[2].id=user-create
spring.cloud.gateway.routes[2].uri=lb://USER-CREATE
spring.cloud.gateway.routes[2].predicates=Path=/user-create/**
spring.cloud.gateway.routes[3].id=category-product
spring.cloud.gateway.routes[3].uri=lb://CATEGORY-PRODUCT
spring.cloud.gateway.routes[3].predicates=Path=/category-product/**
Run Code Online (Sandbox Code Playgroud)
我的类别-产品
@EnableDiscoveryClient …
Run Code Online (Sandbox Code Playgroud) 有类似 swiperrefreshlayout 的东西可以在喷气背包组合中拉动刷新
android ×1
dagger-2 ×1
dagger-hilt ×1
javascript ×1
jsf ×1
jsf-2 ×1
next.js ×1
reactjs ×1
spring-boot ×1