diff --git a/APO1/.idea/workspace.xml b/APO1/.idea/workspace.xml new file mode 100644 index 0000000..1cf4534 --- /dev/null +++ b/APO1/.idea/workspace.xml @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1568512362348 + + + + + + + + + + + + + + + + + + Spring + + + + + + + + + + + + + + + 1.8 + + + + + + + + Trasaction + + + + + + + + 1.8 + + + + + + + + Maven: com.alibaba:druid:1.1.20 + + + + + + + + \ No newline at end of file diff --git a/APO1/pom.xml b/APO1/pom.xml new file mode 100644 index 0000000..75a5e01 --- /dev/null +++ b/APO1/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + + edu.xatu + APO1 + 1.0-SNAPSHOT + + + + org.projectlombok + lombok + 1.18.8 + + + + org.springframework + spring-core + 5.1.9.RELEASE + + + + org.springframework + spring-beans + 5.1.9.RELEASE + + + + org.springframework + spring-context + 5.1.9.RELEASE + + + + + org.springframework + spring-aop + 5.1.9.RELEASE + + + + org.springframework + spring-test + 5.1.9.RELEASE + test + + + + org.springframework + spring-jdbc + 5.1.9.RELEASE + + + + org.springframework + spring-tx + 5.1.9.RELEASE + + + + + org.aspectj + aspectjweaver + 1.9.4 + + + + mysql + mysql-connector-java + 5.1.48 + + + + com.alibaba + druid + 1.1.20 + + + + junit + junit + 4.13-beta-3 + test + + + + org.springframework + spring-webmvc + 5.1.9.RELEASE + + + + \ No newline at end of file diff --git a/APO1/src/main/java/edu/xatu/dao/ChannelDao.java b/APO1/src/main/java/edu/xatu/dao/ChannelDao.java new file mode 100644 index 0000000..66b46af --- /dev/null +++ b/APO1/src/main/java/edu/xatu/dao/ChannelDao.java @@ -0,0 +1,21 @@ +package edu.xatu.dao; + +import edu.xatu.entity.Accout; +import edu.xatu.entity.Channel; + +public interface ChannelDao { + public void addChannel(Channel channel); + + /** + * 根据帐号名查询帐号 + * @param accountName + * @return + */ + public Accout findByAccountName(String accountName); + + /** + * 修改帐号 + * @param account + */ + public void updateAccount(Accout account); +} diff --git a/APO1/src/main/java/edu/xatu/dao/ChannelDaoImpl.java b/APO1/src/main/java/edu/xatu/dao/ChannelDaoImpl.java new file mode 100644 index 0000000..125b21e --- /dev/null +++ b/APO1/src/main/java/edu/xatu/dao/ChannelDaoImpl.java @@ -0,0 +1,41 @@ +package edu.xatu.dao; + +import edu.xatu.entity.Accout; +import edu.xatu.entity.Channel; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.stereotype.Repository; + +import javax.annotation.Resource; +import java.sql.ResultSet; +import java.sql.SQLException; + +@Repository +public class ChannelDaoImpl implements ChannelDao { + @Resource + private JdbcTemplate jdbcTemplate; + public void addChannel(Channel channel) { + String sql="insert into t_channel values(?,?,?)"; + jdbcTemplate.update(sql,channel.getCid(), + channel.getCname(), + channel.getDescription()); + } + + public Accout findByAccountName(String accountName) { + String sql = "select * from t_account where accountName = ?"; + + return jdbcTemplate.queryForObject(sql, new RowMapper() { + public Accout mapRow(ResultSet resultSet, int i) throws SQLException { + Accout a = new Accout(); + a.setAccountName(resultSet.getString("accountName")); + a.setMoney(resultSet.getInt("money")); + return a; + } + },accountName); + } + + public void updateAccount(Accout account) { + String sql = "update t_account set money = ? where accountName = ?"; + jdbcTemplate.update(sql,account.getMoney(),account.getAccountName()); + } +} diff --git a/APO1/src/main/java/edu/xatu/entity/Accout.java b/APO1/src/main/java/edu/xatu/entity/Accout.java new file mode 100644 index 0000000..0f9dae1 --- /dev/null +++ b/APO1/src/main/java/edu/xatu/entity/Accout.java @@ -0,0 +1,9 @@ +package edu.xatu.entity; + +import lombok.Data; + +@Data +public class Accout { + private String accountName; + private int money; +}