Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

Metronic Spring Starterkit with MySQL


Here are instructions on how you can get started with MySQL in Metronic SpringBoot starterkit.

  1. Install MySQL on your machine.
  2. You can use the default root and no password user to login to your MySQL console by running mysql -u root -p
  3. Login to MySQL console and create your database and tables.
  4. In file src/main/resources/application.properties add database properties.

    spring.datasource.url=jdbc:mysql://localhost:3306/db-name
    spring.datasource.username=your-user-name
    spring.datasource.password=your-passowrd
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
    </pre
    >
    Make sure to change db-name with your database name and update your username and password.</li>
    <li>Add dependencies below to <strong>starterkit/pom.xml</strong>.
    <pre lang="xml">
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

  5. Execute mvn clean install.
  6. This is all configuration you need to do to get started with database.
  7. Now you can add your entity, repository, and controller classes to display your database data in markup.

    Entity examples:

    package com.theme.starterkit.models;

    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;

    @Entity
    public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long id;

    public String first_name;
    public String last_name;
    }


    Repository example:

    package com.theme.starterkit.repository;

    import com.theme.starterkit.models.User;
    import org.springframework.data.jpa.repository.JpaRepository;
    import org.springframework.stereotype.Repository;

    @Repository
    public interface UsersRepository extends JpaRepository<User, Long> {
    User findById(long id);
    }
    Controller example.
    package com.theme.starterkit.controller;

    import com.theme.starterkit.repository.UsersRepository;
    import com.theme.starterkit.models.Users;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.PathVariable;

    import com.theme.starterkit.libs.KTTheme;
    import com.theme.starterkit.libs.config.KTThemeBaseConfig;

    @Controller
    public class UserController {
    @Autowired
    private KTTheme theme;

    @Autowired
    private UserRepository userRepository;

    @GetMapping("/user/{id}")
    public String getUserById(@PathVariable long id, Model model) {
    User user = usersRepository.findById(id);
    model.addAttribute("user", user);
    return theme.getPageView("user", "user-details");
    }
    }


    Then you can add user-detail.html inside resources/templates/pages/user with the following code.

    <div layout:fragment="content">
    <h1>User Details</h1>
    <div th:if="${user}">
    <p>User ID: <span th:text="${user.id}" /></p>
    <p>Name: <span th:text="${user.first_name}" /></p>
    <p>Email: <span th:text="${user.last_name}" /></p>
    </div>
    <div th:unless="${user}">
    <p>User not found</p>
    </div>
    </div>



Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Take advantage of the surrounding terrain in escape road 2 to hide and avoid being detected by the police.



In chill guy clicker, every click counts, leading to a rewarding experience that encourages you to keep coming back for more!



To get started with MySQL in the Metronic SpringBoot starter kit, install MySQL, create your database, and configure application.properties with your database details. Add necessary dependencies in pom.xml, then execute mvn clean install to Incredibox Colorbox Mustard complete the setup. Enjoy building your application!


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(