每天记录一点点,慢慢的成长,今天我们学习了ssm,这是我自己总结的笔记,大神勿喷!谢谢,主要代码!! !
spring&springmvc&mybatis整合(注解)
1.jar包
2.引入web.xml文件
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.action</url-pattern></servlet-mapping>3.创建实体类
4.引入一个(类名)dao.xml
<update id="update" parameterType="accounting" > update accounting set money=#{money} where name=#{name} </update> <select id="findMoneyByName" parameterType="string" resultType="accounting"> select * from accounting where name=#{name}</select>5.创建一个(类名)dao
public void update(Accounting a);public Accounting findMoneyByName(String name);6.写service
public void remit(String from,String to,double money);7.写serviceimpl
@Servicepublic class AccountServiceImpl implements AccountService { @Autowired private AccountDao ad; @Override public void remit(String from, String to, double money) { Accounting fromAccount=ad.findMoneyByName(from); fromAccount.setMoney(fromAccount.getMoney()-money); ad.update(fromAccount); Accounting toAccount=ad.findMoneyByName(to); toAccount.setMoney(toAccount.getMoney()+money); ad.update(toAccount); }}8.引入applicationContext.xml
<beans xmlns="http://ponent-scan></beans>11.jsp页面编写
//index.jsp: <form action="account_execute.action" method="post"> 汇款人:<input type="text" name="from"/> 收款人:<input type="text" name="to"/> 钱数:<input type="text" name="money"/> <input type="submit"/> </form>//message.jsp${message }以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。