Skip to content

Commit

Permalink
Merge pull request #43 from WangGithub0/issue-41
Browse files Browse the repository at this point in the history
change the customer id generation strategy
  • Loading branch information
NisargPipaliya authored Jul 15, 2024
2 parents 327c8be + 40dfd66 commit 057cfcf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class User {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;

@Column(unique = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;

import com.jtspringproject.JtSpringProject.dao.userDao;
Expand All @@ -19,7 +20,12 @@ public List<User> getUsers(){
}

public User addUser(User user) {
return this.userDao.saveUser(user);
try {
return this.userDao.saveUser(user);
} catch (DataIntegrityViolationException e) {
// handle unique constraint violation, e.g., by throwing a custom exception
throw new RuntimeException("Add user error");
}
}

public User checkLogin(String username,String password) {
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@

### Database

MySQL or MariaDB can be used as the database for this project. The database connection can be configured in the `application.properties` file, with the appropriate values for the following properties:
(you'd better use another username not root)
MySQL or MariaDB can be used as the database for this project. The database connection can be configured in the `src/main/resources/application.properties` file, with the appropriate values for the following properties:

**( You'd better use another username not root, and ensure that the user has the corresponding permissions for the database. )**

```properties
db.url=jdbc:mysql://[ip address of db]:[port of db]/ecommjava?createDatabaseIfNotExist=true
db.username=[username]
Expand Down

0 comments on commit 057cfcf

Please sign in to comment.