User类
package com.example.demo;
public class User {
private Integer score;
private String name;
public User(String name2,int score) {
this.name = name2;
this.score=score;
}
public User(String name) {
this.name=name;
}
public String getName() {
return name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public void setName(String name) {
this.name = name;
}
}
Dao层
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
@Repository
public class UserDao {
@Autowired
private JdbcTemplate jdbcTemplate;
public void save(User use) {
// TODO Auto-generated method stub
jdbcTemplate.update("insert into appuser (name,score) values(?,?)", use.getName(),use.getScore());
}
public void gx(User use) {
jdbcTemplate.update("update appuser set score=11 where name=(?)", use.getName());
}
}
Service层
package com.example.demo;
public interface Userservice {
void save(User use);
void gengxin(User use);
}
接口实现层
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserserviceImpl implements Userservice{
@Autowired
private UserDao dao;
@Override
public void save(User use) {
dao.save(use);
}
@Override
public void gengxin(User use) {
dao.gx(use);
}
}
具体实现类
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class UserController {
@Autowired
private UserserviceImpl userservice;
@RequestMapping("/save")
public String save(String name,Integer score) {
User use = new User("qw",0);
userservice.save(use);
return "save successfully!";
}
@RequestMapping("/gengxin")
public String gengxin(String name) {
User use = new User("sxf");
userservice.gengxin(use);
return "update successfully!";
}
}

本文介绍了一个基于Java的用户管理系统的设计与实现,包括User类的定义,Dao层、Service层及其实现层的具体操作,以及RESTful API的使用。系统通过JdbcTemplate进行数据库操作,实现了用户的保存和更新功能。
579

被折叠的 条评论
为什么被折叠?



