#linking login info to database

1 messages · Page 1 of 1 (latest)

spring tide
#

im new with java i made a simple login page and i want to link it to a database but didnt know how everything i tried didnt work .

light jungleBOT
#

<@&987246584574140416> please have a look, thanks.

median remnant
#

What do you mean link it to a database? You mean you want to store the info in say a MySQL db?

faint stratus
# spring tide im new with java i made a simple login page and i want to link it to a databas...

If you're a beginner, you'd better start with the basics of java and then move on to web development. I'll assume you're already using Spring, so you need:

  • Create table in your db like 'users'
  • Create User entity with @Entity annotation and declare all columns of 'users' table
  • [Optional] Create UserCreateDto/UserReadDto, if you worrying about security.
  • Create controllers layer to handling requests
#
  • Also, don't forget to declar the dependency to your DB in build.gradle/xml
#

After that, I recommend using Thymeleaf to link controller and your login page

#

login.html:

<form th:action="@{/login}" method="post">
//code-code-code...
    </form>

UserController:

@Controller
@RequiredArgsConstructor
public class UserCreateController {
    @GetMapping("/login")
    public String loginPage() {
        return "user/login";
    }
}
light jungleBOT
abstract niche
#

give more context on your problem