我有一个使用 JPA 的 spring boot 项目,所以我试图使用它们的 Id 将两个表映射到第三个表中:例如,我有一个优惠券类,我有一个客户类,我想将客户 ID 和优惠券 ID 放入第三个桌子。
我有优惠券:
@Entity
@Table(name = "coupons")
public class Coupon {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long coup_id;
private String title;
private String start;
private String end;
private int amount;
private String type;
private String message;
private double price;
private String image;
@ManyToMany(mappedBy = "coupons")
private List<Customer> customers;
Run Code Online (Sandbox Code Playgroud)
我有客户:
@Entity
@Table(name="customers")
public class Customer {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int cust_id;
@Size(min=1,message="is required")
private String cust_name;
@Size(min = 1, message = …Run Code Online (Sandbox Code Playgroud) 我正在开发一个 asp.net 核心 mvc 项目,并尝试将一个数据库对象注入到视图中,以便在视图中从中检索一些东西。
我将该类注入到 startup.cs 中并使用了 @inject,但仍然出现异常。
InvalidOperationException: 没有注册“DbServices.CredentialDb”类型的服务。
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
Run Code Online (Sandbox Code Playgroud)
这是 Startup.cs ConfigureServices 方法:
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
Run Code Online (Sandbox Code Playgroud)
这是我添加数据库访问类的地方:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddIdentity<ApplicationUser, IdentityRole>(
options => options.User.AllowedUserNameCharacters = null)
.AddEntityFrameworkStores<AppDbContext>();
services.AddControllersWithViews();
services.AddDbContextPool<AppDbContext>(
options => options.UseSqlServer(
_config.GetConnectionString("AutoLoverDbConnection"),
x => x.MigrationsAssembly("AutoMatcherProjectAss"))
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
services.AddSingleton<ISessionManager, ClientSIdeSessionManager>();
services.AddHttpContextAccessor();
services.AddSession();
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies
// is needed for a given request.
options.CheckConsentNeeded = context => …Run Code Online (Sandbox Code Playgroud) 这是我不明白的事情,因为如果数组未排序,则意味着在对数组进行排序时,数组中任何元素的位置都无关紧要,如果有两个,则应考虑对数组进行排序所依据的键具有相同值的键,为什么默认返回到原始数组以检查其排序前的位置?是不是仅仅因为这是它唯一的可能性?