i have just started spring boot so i might be making silly mistakes.I am making a regiser.html page which is linked to login page after entering username id and password in register page when we click on submit button it takes us to login page and the data we store will be stored in register table of Mysql.
In login page when we enter the username and password it will check weather this username and password is present in register table of mysql.
If it is present then it will take us to chatpage were we can enter the data and on clicking on submit button it will get stored in the storechat table of the mysql. And if the username and password is not present in the register table of the mysql then it will show that user is not present in the login page itself.
i am getting this error:
Prediction Mode AltAndCOntextMap[JavaApplication]C:/Program FIlesjavajdk -17binjavaw.exe
this is my MyService.java code.
<code>package com.example.chatdemo.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.chatdemo.Entity.Exwhich;
import com.example.chatdemo.Repository.Checkdata;
private Checkdata checkdata1;
public boolean checkexist(String newuser,String newpass) {
Exwhich exwhich= checkdata1.samemethod(newuser,newpass);
<code>package com.example.chatdemo.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.chatdemo.Entity.Exwhich;
import com.example.chatdemo.Repository.Checkdata;
@Service
public class MyService {
@Autowired
private Checkdata checkdata1;
public boolean checkexist(String newuser,String newpass) {
Exwhich exwhich= checkdata1.samemethod(newuser,newpass);
return exwhich!= null;
}
}
</code>
package com.example.chatdemo.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.chatdemo.Entity.Exwhich;
import com.example.chatdemo.Repository.Checkdata;
@Service
public class MyService {
@Autowired
private Checkdata checkdata1;
public boolean checkexist(String newuser,String newpass) {
Exwhich exwhich= checkdata1.samemethod(newuser,newpass);
return exwhich!= null;
}
}
this is my repository (Registerrepo.java) code:
<code>package com.example.chatdemo.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.example.chatdemo.Entity.EntityClass;
public interface Registerrepo extends JpaRepository<EntityClass,String> {
<code>package com.example.chatdemo.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.example.chatdemo.Entity.EntityClass;
public interface Registerrepo extends JpaRepository<EntityClass,String> {
}
</code>
package com.example.chatdemo.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.example.chatdemo.Entity.EntityClass;
public interface Registerrepo extends JpaRepository<EntityClass,String> {
}
this is my another repository named checkdata.java
<code>package com.example.chatdemo.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.example.chatdemo.Entity.Exwhich;
public interface Checkdata extends JpaRepository<Exwhich,Long> {
Exwhich samemethod( String newuser, String newpass);
<code>package com.example.chatdemo.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.example.chatdemo.Entity.Exwhich;
public interface Checkdata extends JpaRepository<Exwhich,Long> {
Exwhich samemethod( String newuser, String newpass);
}
</code>
package com.example.chatdemo.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.example.chatdemo.Entity.Exwhich;
public interface Checkdata extends JpaRepository<Exwhich,Long> {
Exwhich samemethod( String newuser, String newpass);
}
this is my controller file named Controller1.java
<code>package com.example.chatdemo.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.example.chatdemo.Entity.EntityClass;
import com.example.chatdemo.Repository.Registerrepo;
import com.example.chatdemo.Service.MyService;
import jakarta.persistence.Entity;
public class Controller1 {
private Registerrepo reopo;
@GetMapping("/showchatpage")
public String getnewdata() {
public String storedatabase(@ModelAttribute EntityClass E)
public class LoginController{
private MyService mynewservice;
public String login(@RequestParam("mynewuser") String newuser,
@RequestParam("newpass") String newpass, Model model) {
boolean number=mynewservice.checkexist(newuser,newpass);
return "redirect:/showchatpage";
model.addAttribute("message","user dont exist");
<code>package com.example.chatdemo.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.example.chatdemo.Entity.EntityClass;
import com.example.chatdemo.Repository.Registerrepo;
import com.example.chatdemo.Service.MyService;
import jakarta.persistence.Entity;
@RestController
public class Controller1 {
@Autowired
private Registerrepo reopo;
@GetMapping("/showchatpage")
public String getnewdata() {
return "register";
}
@PostMapping("/submit")
public String storedatabase(@ModelAttribute EntityClass E)
{
reopo.save(E);
return "abcd";
}
@Controller
public class LoginController{
@Autowired
private MyService mynewservice;
@PostMapping("/login")
public String login(@RequestParam("mynewuser") String newuser,
@RequestParam("newpass") String newpass, Model model) {
boolean number=mynewservice.checkexist(newuser,newpass);
if(number) {
return "redirect:/showchatpage";
}
else {
model.addAttribute("message","user dont exist");
return "login";
}
}
}
}
</code>
package com.example.chatdemo.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.example.chatdemo.Entity.EntityClass;
import com.example.chatdemo.Repository.Registerrepo;
import com.example.chatdemo.Service.MyService;
import jakarta.persistence.Entity;
@RestController
public class Controller1 {
@Autowired
private Registerrepo reopo;
@GetMapping("/showchatpage")
public String getnewdata() {
return "register";
}
@PostMapping("/submit")
public String storedatabase(@ModelAttribute EntityClass E)
{
reopo.save(E);
return "abcd";
}
@Controller
public class LoginController{
@Autowired
private MyService mynewservice;
@PostMapping("/login")
public String login(@RequestParam("mynewuser") String newuser,
@RequestParam("newpass") String newpass, Model model) {
boolean number=mynewservice.checkexist(newuser,newpass);
if(number) {
return "redirect:/showchatpage";
}
else {
model.addAttribute("message","user dont exist");
return "login";
}
}
}
}
this is my Entity class named EntityClass.java
<code>package com.example.chatdemo.Entity;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
public class EntityClass {
public String getName() {
public void setName(String name) {
public String getPassword() {
public void setPassword(String password) {
this.password = password;
public String toString() {
return "Entity [name=" + name + ", password=" + password + "]";
<code>package com.example.chatdemo.Entity;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name="register")
public class EntityClass {
@Id
String name;
String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "Entity [name=" + name + ", password=" + password + "]";
}
}
</code>
package com.example.chatdemo.Entity;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name="register")
public class EntityClass {
@Id
String name;
String password;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "Entity [name=" + name + ", password=" + password + "]";
}
}
this is my another Entity class names Exwhich.java
<code>package com.example.chatdemo.Entity;
<code>package com.example.chatdemo.Entity;
public class Exwhich {
}
</code>
package com.example.chatdemo.Entity;
public class Exwhich {
}
i am getting no error inside code just getting error on running code.