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!";
}
}